From 254dea1bcd1aaf71cc0a87f18e71681b07c0be61 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Tue, 5 Oct 2021 14:46:13 +0200 Subject: [PATCH] Update src/functor.jl --- src/functor.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/functor.jl b/src/functor.jl index e082cd6..312a498 100644 --- a/src/functor.jl +++ b/src/functor.jl @@ -193,6 +193,9 @@ julia> fcollect(m, exclude = v -> Functors.isleaf(v)) ``` """ function fcollect(x; output = [], cache = Base.IdSet(), exclude = v -> false) + # note: we don't have an `OrderedIdSet`, so we use an `IdSet` for the cache + # (to ensure we get exactly 1 copy of each distinct array), and a usual `Vector` + # for the results, to preserve traversal order (important downstream!). x in cache && return output if !exclude(x) push!(cache, x)