mirror of
https://github.com/IBM/fp-go.git
synced 2025-11-23 22:14:53 +02:00
fix: auto generate more sequence operations
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@@ -230,7 +230,7 @@ func Intersperse[A any](middle A) func([]A) []A {
|
||||
}
|
||||
|
||||
func Intercalate[A any](m M.Monoid[A]) func(A) func([]A) A {
|
||||
concatAll := ConcatAll[A](m)(m.Empty())
|
||||
concatAll := ConcatAll[A](m)
|
||||
return func(middle A) func([]A) A {
|
||||
return Match(m.Empty, F.Flow2(Intersperse(middle), concatAll))
|
||||
}
|
||||
|
||||
@@ -16,10 +16,9 @@
|
||||
package array
|
||||
|
||||
import (
|
||||
F "github.com/IBM/fp-go/function"
|
||||
M "github.com/IBM/fp-go/magma"
|
||||
M "github.com/IBM/fp-go/monoid"
|
||||
)
|
||||
|
||||
func ConcatAll[A any](m M.Magma[A]) func(A) func([]A) A {
|
||||
return F.Bind1st(Reduce[A, A], m.Concat)
|
||||
func ConcatAll[A any](m M.Monoid[A]) func([]A) A {
|
||||
return Reduce(m.Concat, m.Empty())
|
||||
}
|
||||
|
||||
@@ -20,16 +20,16 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
M "github.com/IBM/fp-go/magma"
|
||||
M "github.com/IBM/fp-go/monoid"
|
||||
)
|
||||
|
||||
var subInt = M.MakeMagma(func(first int, second int) int {
|
||||
var subInt = M.MakeMonoid(func(first int, second int) int {
|
||||
return first - second
|
||||
})
|
||||
}, 0)
|
||||
|
||||
func TestConcatAll(t *testing.T) {
|
||||
|
||||
var subAll = ConcatAll(subInt)(0)
|
||||
var subAll = ConcatAll(subInt)
|
||||
|
||||
assert.Equal(t, subAll([]int{1, 2, 3}), -6)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user