A new relevant package, not yet registered, is CollectAs.jl. Use it like:
using CollectAs: collect_as
collect_as(Memory, any_iterator)
collect_as(Memory{Float32}, any_iterator)
However collect_as
is not just for Memory
, it’s basically for any collection type (as long as there’s an implementation). In that way it generalizes collect
, which only allows specifying the element type.
The package currently resides on my personal Github namespace, but I hope to be able to move it to JuliaCollections before registering it.
EDIT: it’s still not registered, still in the process, currently it’s named Collects.jl, and there’s a dedicated topic here on the forum: New package: Collects.jl - meant to improve upon and generalize the interface of collect