Skip to content

Commit

Permalink
fix: add Join
Browse files Browse the repository at this point in the history
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
  • Loading branch information
CarstenLeue committed Jan 17, 2024
1 parent a14feff commit 89c3425
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions string/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions string/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ package string
import (
"testing"

A "github.com/IBM/fp-go/array"
"github.com/stretchr/testify/assert"
)

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]()))
}

0 comments on commit 89c3425

Please sign in to comment.