Skip to content

Commit

Permalink
Fix #16742, document Iterators.filter (#21550)
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb authored and ararslan committed Apr 26, 2017
1 parent c326b1c commit ba8e3bb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ struct Filter{F,I}
itr::I
end

"""
Iterators.filter(flt, itr)
Given a predicate function `flt` and an iterable object `itr`, return an
iterable object which upon iteration yields the elements `x` of `itr` that
satisfy `flt(x)`. The order of the original iterator is preserved.
This function is *lazy*; that is, it is guaranteed to return in ``Θ(1)`` time
and use ``Θ(1)`` additional space, and `flt` will not be called by an
invocation of `filter`. Calls to `flt` will be made when iterating over the
returned iterable object. These calls are not cached and repeated calls will be
made when reiterating.
See [`Base.filter`](@ref) for an eager implementation of filtering for arrays.
"""
filter(flt, itr) = Filter(flt, itr)

start(f::Filter) = start_filter(f.flt, f.itr)
Expand Down

0 comments on commit ba8e3bb

Please sign in to comment.