@@ -2,7 +2,6 @@ package iter_test
22
33import  (
44	"fmt" 
5- 	"iter" 
65	"maps" 
76	"slices" 
87	"testing" 
@@ -30,11 +29,18 @@ func TestMapEmpty(t *testing.T) {
3029	assert .Empty [int ](t , slices .Collect (fn .Map (fn .Exhausted [int ](), func (int ) int  { return  0  })))
3130}
3231
33- func  TestMapTerminateEarly (t  * testing.T ) {
32+ func  TestMapYieldFalse (t  * testing.T ) {
3433	t .Parallel ()
3534
36- 	_ , stop  :=  iter .Pull (fn .Map (slices .Values ([]int {1 , 2 , 3 }), func (int ) int  { return  0  }))
37- 	stop ()
35+ 	numbers  :=  fn .Map (slices .Values ([]int {1 , 2 , 3 , 4 , 5 }), func (a  int ) int  { return  a  +  1  })
36+ 
37+ 	values  :=  []int {}
38+ 	numbers (func (v  int ) bool  {
39+ 		values  =  append (values , v )
40+ 		return  false 
41+ 	})
42+ 
43+ 	assert .SliceEqual (t , []int {2 }, values )
3844}
3945
4046func  ExampleMap2 () {
@@ -58,11 +64,23 @@ func TestMap2Empty(t *testing.T) {
5864	assert .Equal (t , len (maps .Collect (fn .Map2 (fn .Exhausted2 [int , int ](), doubleBoth ))), 0 )
5965}
6066
61- func  TestMap2TerminateEarly (t  * testing.T ) {
67+ func  TestMap2YieldFalse (t  * testing.T ) {
6268	t .Parallel ()
6369
64- 	doubleBoth  :=  func (n , m  int ) (int , int ) { return  n  *  2 , m  *  2  }
65- 
66- 	_ , stop  :=  iter .Pull2 (fn .Map2 (maps .All (map [int ]int {1 : 2 }), doubleBoth ))
67- 	stop ()
70+ 	numberPairs  :=  fn .Zip (slices .Values ([]int {1 , 2 , 3 }), slices .Values ([]int {3 , 4 , 5 }))
71+ 	numbers  :=  fn .Map2 (
72+ 		numberPairs ,
73+ 		func (a , b  int ) (int , int ) {
74+ 			return  a  +  1 , b  +  2 
75+ 		},
76+ 	)
77+ 
78+ 	var  a , b  int 
79+ 	numbers (func (v , w  int ) bool  {
80+ 		a , b  =  v , w 
81+ 		return  false 
82+ 	})
83+ 
84+ 	assert .Equal (t , a , 2 )
85+ 	assert .Equal (t , b , 5 )
6886}
0 commit comments