1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-12-01 22:41:43 +02:00

fix: add Ap for iterators

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-25 17:34:32 +02:00
parent 41b792b23a
commit d2346b016e
3 changed files with 82 additions and 2 deletions

View File

@@ -73,6 +73,11 @@ func Flatten[U any](ma Iterator[Iterator[U]]) Iterator[U] {
return G.Flatten[Iterator[Iterator[U]], Iterator[U]](ma)
}
// From constructs an [Iterator] from a set of variadic arguments
func From[U any](data ...U) Iterator[U] {
return G.From[Iterator[U]](data...)
}
// MakeBy returns an [Iterator] with `n` elements initialized with `f(i)`
func MakeBy[FCT ~func(int) U, U any](n int, f FCT) Iterator[U] {
return G.MakeBy[Iterator[U]](n, f)
@@ -82,3 +87,18 @@ func MakeBy[FCT ~func(int) U, U any](n int, f FCT) Iterator[U] {
func Replicate[U any](n int, a U) Iterator[U] {
return G.Replicate[Iterator[U]](n, a)
}
// FilterMap filters and transforms the content of an iterator
func FilterMap[U, V any](f func(U) O.Option[V]) func(ma Iterator[U]) Iterator[V] {
return G.FilterMap[Iterator[V], Iterator[U]](f)
}
// Filter filters the content of an iterator
func Filter[U any](f func(U) bool) func(ma Iterator[U]) Iterator[U] {
return G.Filter[Iterator[U]](f)
}
// Ap is the applicative functor for iterators
func Ap[U, V any](ma Iterator[U]) func(Iterator[func(U) V]) Iterator[V] {
return G.Ap[Iterator[func(U) V], Iterator[V]](ma)
}