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:
3
samples/readfile/file.json
Normal file
3
samples/readfile/file.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"data": "Carsten"
|
||||
}
|
31
samples/readfile/readfile_test.go
Normal file
31
samples/readfile/readfile_test.go
Normal 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())
|
||||
}
|
Reference in New Issue
Block a user