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

fix: add writer

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-23 21:45:32 +02:00
parent 205b728bda
commit 9e14cd1c00
21 changed files with 8249 additions and 7731 deletions

35
writer/writer_test.go Normal file
View File

@@ -0,0 +1,35 @@
package writer
import (
"fmt"
A "github.com/IBM/fp-go/array"
F "github.com/IBM/fp-go/function"
M "github.com/IBM/fp-go/monoid"
T "github.com/IBM/fp-go/tuple"
)
func doubleAndLog(data int) Writer[[]string, int] {
return func() T.Tuple2[int, []string] {
result := data * 2
return T.MakeTuple2(result, A.Of(fmt.Sprintf("Doubled %d -> %d", data, result)))
}
}
func ExampleLoggingWriter() {
m := A.Monoid[string]()
s := M.ToSemigroup(m)
res := F.Pipe3(
10,
Of[int](m),
Chain[int, int](s)(doubleAndLog),
Chain[int, int](s)(doubleAndLog),
)
fmt.Println(res())
// Output: test
}