github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/internal/examples/loopexamples/loop_iterating_test.go (about) 1 package loopexamples 2 3 import ( 4 "testing" 5 6 "github.com/m4gshm/gollections/loop" 7 "github.com/m4gshm/gollections/loop/range_" 8 ) 9 10 func Test_Iterating_EmbeddedFor(t *testing.T) { 11 12 next := range_.Of(0, 100) 13 for i, ok := next(); ok; i, ok = next() { 14 doOp(i) 15 } 16 17 } 18 19 func Test_Iterating_EmbeddedFor2(t *testing.T) { 20 21 for next, i, ok := range_.Of(0, 100).Crank(); ok; i, ok = next() { 22 doOp(i) 23 } 24 25 } 26 27 func Test_Iterating_ForEach(t *testing.T) { 28 29 range_.Of(0, 100).ForEach(doOp) 30 31 } 32 33 func Test_Iterating_For(t *testing.T) { 34 35 range_.Of(0, 100).For(func(i int) error { 36 if i > 22 { 37 return loop.Break 38 } 39 doOp(i) 40 return loop.Continue 41 }) 42 43 } 44 45 func doOp(i int) { 46 47 }