mirror of
https://github.com/IBM/fp-go.git
synced 2025-06-21 00:19:34 +02:00
fix: add Join
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
@ -32,6 +32,9 @@ var (
|
|||||||
|
|
||||||
// Ord implements the default ordering for strings
|
// Ord implements the default ordering for strings
|
||||||
Ord = ord.FromStrictCompare[string]()
|
Ord = ord.FromStrictCompare[string]()
|
||||||
|
|
||||||
|
// Join joins strings
|
||||||
|
Join = F.Curry2(F.Bind2nd[[]string, string, string])(strings.Join)
|
||||||
)
|
)
|
||||||
|
|
||||||
func Eq(left string, right string) bool {
|
func Eq(left string, right string) bool {
|
||||||
|
@ -18,6 +18,7 @@ package string
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
A "github.com/IBM/fp-go/array"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,3 +26,13 @@ func TestEmpty(t *testing.T) {
|
|||||||
assert.True(t, IsEmpty(""))
|
assert.True(t, IsEmpty(""))
|
||||||
assert.False(t, IsEmpty("Carsten"))
|
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]()))
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user