1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-09-05 20:26:12 +02:00

Compare commits

...

1 Commits

Author SHA1 Message Date
Dr. Carsten Leue
89c34254a9 fix: add Join
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2024-01-17 11:57:26 +01:00
2 changed files with 14 additions and 0 deletions

View File

@@ -32,6 +32,9 @@ var (
// Ord implements the default ordering for strings
Ord = ord.FromStrictCompare[string]()
// Join joins strings
Join = F.Curry2(F.Bind2nd[[]string, string, string])(strings.Join)
)
func Eq(left string, right string) bool {

View File

@@ -18,6 +18,7 @@ package string
import (
"testing"
A "github.com/IBM/fp-go/array"
"github.com/stretchr/testify/assert"
)
@@ -25,3 +26,13 @@ func TestEmpty(t *testing.T) {
assert.True(t, IsEmpty(""))
assert.False(t, IsEmpty("Carsten"))
}
func TestJoin(t *testing.T) {
x := Join(",")(A.From("a", "b", "c"))
assert.Equal(t, x, x)
assert.Equal(t, "a,b,c", Join(",")(A.From("a", "b", "c")))
assert.Equal(t, "a", Join(",")(A.From("a")))
assert.Equal(t, "", Join(",")(A.Empty[string]()))
}