@@ -2,20 +2,20 @@ package iter
22
33import "github.com/BooleanCat/go-functional/option"
44
5- // FilterIter implements `Filter`. See ` Filter`'s documentation .
5+ // FilterIter iterator, see [ Filter] .
66type FilterIter [T any ] struct {
77 iter Iterator [T ]
88 fun func (T ) bool
99 exhausted bool
1010}
1111
12- // Filter instantiates a ` FilterIter` that selectively yields only results that
13- // cause the provided function to return `true`.
12+ // Filter instantiates a [* FilterIter] that selectively yields only results
13+ // that cause the provided function to return `true`.
1414func Filter [T any ](iter Iterator [T ], fun func (T ) bool ) * FilterIter [T ] {
1515 return & FilterIter [T ]{iter , fun , false }
1616}
1717
18- // Next implements the Iterator interface for `Filter` .
18+ // Next implements the [ Iterator] interface.
1919func (iter * FilterIter [T ]) Next () option.Option [T ] {
2020 if iter .exhausted {
2121 return option .None [T ]()
@@ -36,36 +36,39 @@ func (iter *FilterIter[T]) Next() option.Option[T] {
3636
3737var _ Iterator [struct {}] = new (FilterIter [struct {}])
3838
39- // Collect is an alternative way of invoking Collect(iter)
39+ // Collect is a convenience method for [Collect], providing this iterator as
40+ // an argument.
4041func (iter * FilterIter [T ]) Collect () []T {
4142 return Collect [T ](iter )
4243}
4344
44- // Drop is an alternative way of invoking Drop(iter)
45+ // Drop is a convenience method for [Drop], providing this iterator as an
46+ // argument.
4547func (iter * FilterIter [T ]) Drop (n uint ) * DropIter [T ] {
4648 return Drop [T ](iter , n )
4749}
4850
49- // Take is an alternative way of invoking Take(iter)
51+ // Take is a convenience method for [Take], providing this iterator as an
52+ // argument.
5053func (iter * FilterIter [T ]) Take (n uint ) * TakeIter [T ] {
5154 return Take [T ](iter , n )
5255}
5356
54- // Exclude instantiates a ` FilterIter` that selectively yields only results that
55- // cause the provided function to return `false`.
57+ // Exclude instantiates a [* FilterIter] that selectively yields only results
58+ // that cause the provided function to return `false`.
5659func Exclude [T any ](iter Iterator [T ], fun func (T ) bool ) * FilterIter [T ] {
5760 inverse := func (t T ) bool { return ! fun (t ) }
5861 return & FilterIter [T ]{iter , inverse , false }
5962}
6063
61- // FilterMapIter implements `FilterMap`. See ` FilterMap`'s documentation .
64+ // FilterMapIter iterator, see [ FilterMap] .
6265type FilterMapIter [T any , U any ] struct {
6366 iter Iterator [T ]
6467 fn func (T ) option.Option [U ]
6568 exhausted bool
6669}
6770
68- // Next implements the Iterator interface for `FilterMapIter` .
71+ // Next implements the [ Iterator] interface.
6972func (iter * FilterMapIter [T , U ]) Next () option.Option [U ] {
7073 if iter .exhausted {
7174 return option .None [U ]()
@@ -87,24 +90,27 @@ func (iter *FilterMapIter[T, U]) Next() option.Option[U] {
8790
8891var _ Iterator [struct {}] = new (FilterMapIter [struct {}, struct {}])
8992
90- // Accepts an underlying iterator as data source and a filtering + mapping function
91- // it allows the user to filter elements by returning a None variant and to transform
92- // elements by returning a Some variant .
93+ // FilterMap instantiates a [*FilterMapIter] that selectively yields only
94+ // results that cause the provided function to return `true` with a map
95+ // operation performed on them .
9396func FilterMap [T any , U any ](itr Iterator [T ], fun func (T ) option.Option [U ]) * FilterMapIter [T , U ] {
9497 return & FilterMapIter [T , U ]{itr , fun , false }
9598}
9699
97- // Collect is an alternative way of invoking Collect(iter)
100+ // Collect is a convenience method for [Collect], providing this iterator as
101+ // an argument.
98102func (iter * FilterMapIter [T , U ]) Collect () []U {
99103 return Collect [U ](iter )
100104}
101105
102- // Drop is an alternative way of invoking Drop(iter)
106+ // Drop is a convenience method for [Drop], providing this iterator as an
107+ // argument.
103108func (iter * FilterMapIter [T , U ]) Drop (n uint ) * DropIter [U ] {
104109 return Drop [U ](iter , n )
105110}
106111
107- // Take is an alternative way of invoking Take(iter)
112+ // Take is a convenience method for [Take], providing this iterator as an
113+ // argument.
108114func (iter * FilterMapIter [T , U ]) Take (n uint ) * TakeIter [U ] {
109115 return Take [U ](iter , n )
110116}
0 commit comments