mirror of
https://github.com/IBM/fp-go.git
synced 2025-11-25 22:21:49 +02:00
fix: better tests for Lazy
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -22,18 +22,56 @@ import (
|
||||
|
||||
// SequenceT converts n inputs of higher kinded types into a higher kinded types of n strongly typed values, represented as a tuple
|
||||
|
||||
// SequenceT1 combines a single lazy computation into a lazy tuple.
|
||||
// This is mainly useful for consistency with the other SequenceT functions.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// lazy1 := lazy.Of(42)
|
||||
// result := lazy.SequenceT1(lazy1)()
|
||||
// // result is tuple.Tuple1[int]{F1: 42}
|
||||
func SequenceT1[A any](a Lazy[A]) Lazy[tuple.Tuple1[A]] {
|
||||
return io.SequenceT1(a)
|
||||
}
|
||||
|
||||
// SequenceT2 combines two lazy computations into a lazy tuple of two elements.
|
||||
// Both computations are evaluated when the result is evaluated.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// lazy1 := lazy.Of(42)
|
||||
// lazy2 := lazy.Of("hello")
|
||||
// result := lazy.SequenceT2(lazy1, lazy2)()
|
||||
// // result is tuple.Tuple2[int, string]{F1: 42, F2: "hello"}
|
||||
func SequenceT2[A, B any](a Lazy[A], b Lazy[B]) Lazy[tuple.Tuple2[A, B]] {
|
||||
return io.SequenceT2(a, b)
|
||||
}
|
||||
|
||||
// SequenceT3 combines three lazy computations into a lazy tuple of three elements.
|
||||
// All computations are evaluated when the result is evaluated.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// lazy1 := lazy.Of(42)
|
||||
// lazy2 := lazy.Of("hello")
|
||||
// lazy3 := lazy.Of(true)
|
||||
// result := lazy.SequenceT3(lazy1, lazy2, lazy3)()
|
||||
// // result is tuple.Tuple3[int, string, bool]{F1: 42, F2: "hello", F3: true}
|
||||
func SequenceT3[A, B, C any](a Lazy[A], b Lazy[B], c Lazy[C]) Lazy[tuple.Tuple3[A, B, C]] {
|
||||
return io.SequenceT3(a, b, c)
|
||||
}
|
||||
|
||||
// SequenceT4 combines four lazy computations into a lazy tuple of four elements.
|
||||
// All computations are evaluated when the result is evaluated.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// lazy1 := lazy.Of(42)
|
||||
// lazy2 := lazy.Of("hello")
|
||||
// lazy3 := lazy.Of(true)
|
||||
// lazy4 := lazy.Of(3.14)
|
||||
// result := lazy.SequenceT4(lazy1, lazy2, lazy3, lazy4)()
|
||||
// // result is tuple.Tuple4[int, string, bool, float64]{F1: 42, F2: "hello", F3: true, F4: 3.14}
|
||||
func SequenceT4[A, B, C, D any](a Lazy[A], b Lazy[B], c Lazy[C], d Lazy[D]) Lazy[tuple.Tuple4[A, B, C, D]] {
|
||||
return io.SequenceT4(a, b, c, d)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user