@@ -381,7 +381,7 @@ numbers := itx.FromMap(map[int]string{1: "one"}).Cycle().Take(5)
381381> otherwise it's likely to result in an infinite while loop. Consider bounding the size of the
382382> iterator before consuming (e.g. using [ Take] ( #take ) ).
383383
384- ### Drop
384+ < h3 id = " drop " > Drop & DropWhile</ h3 >
385385
386386Drop yields all values from a delegate iterator after dropping a number of values from the
387387beginning. Values are not dropped immediately, but when consumption begins.
@@ -402,6 +402,24 @@ numbers := it.Drop2(maps.All(map[int]string{1: "one", 2: "two", 3: "three"}), 1)
402402numbers := itx.FromMap (map [int ]string {1 : " one" , 2 : " two" , 3 : " three" }).Drop (1 )
403403```
404404
405+ DropWhile drops values from the provided iterator whilst the predicate returns true for each value.
406+ After the first value results in the predicate returning false, the iterator resumes as normal.
407+
408+ ``` go
409+ slices.Collect (it.DropWhile (slices.Values ([]int {1 , 2 , 3 , 4 , 5 }), filter.LessThan (3 )))
410+
411+ // Chainable
412+ itx.FromSlice ([]int {1 , 2 , 3 , 4 , 5 }).DropWhile (filter.LessThan (3 )).Collect ()
413+
414+ lessThanThree := func (string , number int ) { return number < 3 }
415+
416+ // Taking from iter.Seq2
417+ maps.Collect (it.DropWhile2 (maps.All (map [string ]int {" one" : 1 , " four" : 4 }), lessThanThree))
418+
419+ // As above, but chainable
420+ itx.FromMap (map [string ]int {" one" : 1 , " four" : 4 }).DropWhile (lessThanThree).Collect ()
421+ ```
422+
405423### Enumerate
406424
407425Enumerating an [ iter.Seq] ( https://pkg.go.dev/iter#Seq ) like iterator returns an
@@ -713,20 +731,18 @@ TakeWhile yields values from the provided iterator whilst the predicate returns
713731After the first value results in the predicate returning false, the iterator is exhausted.
714732
715733``` go
716- lessThanThree := func (number int ) { number < 3 }
717-
718- slices.Collect (it.TakeWhile (slices.Values ([]int {1 , 2 , 3 }), lessThanThree))
734+ slices.Collect (it.TakeWhile (slices.Values ([]int {1 , 2 , 3 }), filter.LessThan (3 )))
719735
720736// Chainable
721- itx.FromSlice ([]int {1 , 2 , 3 }).TakeWhile (lessThanThree ).Collect ()
737+ itx.FromSlice ([]int {1 , 2 , 3 }).TakeWhile (filter. LessThan ( 3 ) ).Collect ()
722738
723- lessThanThreeRight := func (_ string , number int ) { return number < 3 }
739+ lessThanThree := func (string , number int ) { return number < 3 }
724740
725741// Taking from iter.Seq2
726- maps.Collect (it.TakeWhile2 (maps.All (map [string ]int {" one" : 1 , " four" : 4 }), lessThanThreeRight ))
742+ maps.Collect (it.TakeWhile2 (maps.All (map [string ]int {" one" : 1 , " four" : 4 }), lessThanThree ))
727743
728744// As above, but chainable
729- itx.FromMap (map [string ]int {" one" : 1 , " four" : 4 }).TakeWhile (lessThanThreeRight ).Collect ()
745+ itx.FromMap (map [string ]int {" one" : 1 , " four" : 4 }).TakeWhile (lessThanThree ).Collect ()
730746```
731747
732748### Zip, Left & Right
0 commit comments