1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-08-10 22:31:32 +02:00

fix: implement FoldMap

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-08-10 18:08:11 +02:00
parent 39c6108bf5
commit 1b1dccc551
11 changed files with 306 additions and 1 deletions

View File

@@ -18,10 +18,12 @@ package record
import (
"fmt"
"sort"
"strings"
"testing"
"github.com/IBM/fp-go/internal/utils"
O "github.com/IBM/fp-go/option"
S "github.com/IBM/fp-go/string"
"github.com/stretchr/testify/assert"
)
@@ -99,3 +101,33 @@ func TestFilterChain(t *testing.T) {
"c": "c3",
}, res)
}
func ExampleFoldMap() {
src := map[string]string{
"a": "a",
"b": "b",
"c": "c",
}
fold := FoldMap[string, string](S.Monoid)(strings.ToUpper)
fmt.Println(fold(src))
// Output: ABC
}
func ExampleValuesOrd() {
src := map[string]string{
"c": "a",
"b": "b",
"a": "c",
}
getValues := ValuesOrd[string](S.Ord)
fmt.Println(getValues(src))
// Output: [c b a]
}