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

fix: add missing chain methods

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-15 23:27:45 +02:00
parent 84c3e3ff88
commit bf04dad87c
10 changed files with 157 additions and 18 deletions

View File

@@ -0,0 +1,3 @@
{
"data": "Carsten"
}

View File

@@ -0,0 +1,31 @@
package readfile
import (
"context"
"testing"
R "github.com/ibm/fp-go/context/readerioeither"
"github.com/ibm/fp-go/context/readerioeither/file"
E "github.com/ibm/fp-go/either"
F "github.com/ibm/fp-go/function"
IO "github.com/ibm/fp-go/io"
J "github.com/ibm/fp-go/json"
"github.com/stretchr/testify/assert"
)
type RecordType struct {
Data string `json:"data"`
}
func TestReadSingleFile(t *testing.T) {
data := F.Pipe2(
file.ReadFile("./file.json"),
R.ChainEitherK(J.Unmarshal[RecordType]),
R.ChainFirstIOK(IO.Logf[RecordType]("Log: %v")),
)
result := data(context.Background())
assert.Equal(t, E.Of[error](RecordType{"Carsten"}), result())
}