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:
@@ -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]
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user