mirror of
https://github.com/IBM/fp-go.git
synced 2025-06-19 00:17:48 +02:00
initial checkin
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
28
array/traverse_test.go
Normal file
28
array/traverse_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package array
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
O "github.com/ibm/fp-go/option"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type ArrayType = []int
|
||||
|
||||
func TestTraverse(t *testing.T) {
|
||||
|
||||
traverse := Traverse(
|
||||
O.Of[ArrayType],
|
||||
O.MonadMap[ArrayType, func(int) ArrayType],
|
||||
O.MonadAp[int, ArrayType],
|
||||
|
||||
func(n int) O.Option[int] {
|
||||
if n%2 == 0 {
|
||||
return O.None[int]()
|
||||
}
|
||||
return O.Of(n)
|
||||
})
|
||||
|
||||
assert.Equal(t, O.None[[]int](), traverse(ArrayType{1, 2}))
|
||||
assert.Equal(t, O.Of(ArrayType{1, 3}), traverse(ArrayType{1, 3}))
|
||||
}
|
Reference in New Issue
Block a user