Skip to content

Commit ba8e3bb

Browse files
TotalVerbararslan
authored andcommitted
Fix #16742, document Iterators.filter (#21550)
1 parent c326b1c commit ba8e3bb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

base/iterators.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@ struct Filter{F,I}
247247
itr::I
248248
end
249249

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

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

0 commit comments

Comments
 (0)