Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter(f, tuple) #32968

Merged
merged 8 commits into from
Dec 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
afoldl magic one-line
Co-authored-by: Takafumi Arakaki <[email protected]>
  • Loading branch information
mcabbott and tkf committed Sep 26, 2019
commit eac113af06b34a7edadde2a9401cfc8766e23aad
12 changes: 2 additions & 10 deletions base/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,8 @@ end

## filter ##

filter(f, t::Tuple) = _filter(f, t, ())
function _filter(f, t::Tuple, r::Tuple)
@_inline_meta
if f(first(t))
return _filter(f, tail(t), (r..., first(t)))
else
return _filter(f, tail(t), r)
end
end
_filter(f, t::Tuple{}, r::Tuple) = r
filter(f, xs::Tuple) = afoldl((ys, x) -> f(x) ? (ys..., x) : ys, (), xs...)

# use Array for long tuples
filter(f, t::Any16) = Tuple(filter(f, collect(t)))

Expand Down