# Materialize transducer into existing storage

**URL:** <https://discourse.julialang.org/t/materialize-transducer-into-existing-storage/87258>\
**Category:** General Usage\
**Tags:** transducers\
**Created:** [September 14, 2022, 7:46am UTC](https://discourse.julialang.org/t/materialize-transducer-into-existing-storage/87258 "2022-09-14T07:46:09Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![mfiano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mfiano/32/37565_2.png) [@mfiano](https://discourse.julialang.org/u/mfiano)\
**Post date:** [September 14, 2022, 2:38pm UTC](https://discourse.julialang.org/t/materialize-transducer-into-existing-storage/87258/6 "2022-09-14T14:38:00Z")

</div>

No that won’t do, as a transducer is not a function. I finally figured something out though that is type-stable, doesn’t allocate, and is extremely fast (thanks to @jakobnissen for the starting point):

```julia
function Base.map!(f::F, dest, kernel::Kernel) where {F}
    foldl(kernel |> Map(f) |> Enumerate(); init=dest) do v, (i, e)
        i > length(dest) && resize!(dest, i)
        v[i] = e
        v
    end
end

```

If anyone sees any room for improvement, I’d like to know, being relatively new to Julia, and extremely new to Transducers.jl myself. Thank you!

---

_[View the full topic](https://discourse.julialang.org/t/materialize-transducer-into-existing-storage/87258)._
