Skip to content

Commit

Permalink
Merge branch 'eph/fcollect' of https://github.com/ericphanson/Functor…
Browse files Browse the repository at this point in the history
…s.jl into eph/fcollect
  • Loading branch information
ericphanson committed Oct 5, 2021
2 parents c1c2421 + 254dea1 commit bd72671
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 @@ -194,6 +194,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 bd72671

Please sign in to comment.