Filter(.., ::Tuple)

Since there is no filter for Tuples, eg

julia> t = (1, 2, 3)
(1, 2, 3)

julia> filter(isodd, t)
ERROR: MethodError: no method matching filter(::typeof(isodd), ::Tuple{Int64,Int64,Int64})
Closest candidates are:
  filter(::Any, ::Array{T,1} where T) at array.jl:2352
  filter(::Any, ::BitArray) at bitarray.jl:1637
  filter(::Any, ::AbstractArray) at array.jl:2313
  ...
Stacktrace:
 [1] top-level scope at none:0

should I convert to vectors and back,

julia> tuple(filter(isodd, [t...])...)
(1, 3)

or is there a better option?

That was moved to Iterators :
Iterators.filter(isodd, (1,2,3))
It does return a new Iterator - which is likely why it doesn’t overload Base.filter directly.
So I guess you need to do something like:

(Iterators.filter(isodd, (1,2,3))...,)
2 Likes