Skip to content

Commit

Permalink
Update src/functor.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson authored Oct 5, 2021
1 parent b020163 commit 254dea1
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/functor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 254dea1

Please sign in to comment.