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

fix: doc and parameter order

Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
This commit is contained in:
Dr. Carsten Leue
2023-07-19 16:20:28 +02:00
parent 34bf3635b9
commit 79834541bf
22 changed files with 91 additions and 34 deletions

View File

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

View File

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

View File

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

View File

@@ -2,8 +2,10 @@ package readfile
import (
"context"
"fmt"
"testing"
A "github.com/IBM/fp-go/array"
R "github.com/IBM/fp-go/context/readerioeither"
"github.com/IBM/fp-go/context/readerioeither/file"
E "github.com/IBM/fp-go/either"
@@ -22,7 +24,7 @@ type RecordType struct {
func TestReadSingleFile(t *testing.T) {
data := F.Pipe2(
file.ReadFile("./file.json"),
file.ReadFile("./data/file.json"),
R.ChainEitherK(J.Unmarshal[RecordType]),
R.ChainFirstIOK(IO.Logf[RecordType]("Log: %v")),
)
@@ -31,3 +33,26 @@ func TestReadSingleFile(t *testing.T) {
assert.Equal(t, E.Of[error](RecordType{"Carsten"}), result())
}
func idxToFilename(idx int) string {
return fmt.Sprintf("./data/file%d.json", idx+1)
}
// TestReadMultipleFiles reads the content of a multiple from disk and parses them into
// structs
func TestReadMultipleFiles(t *testing.T) {
data := F.Pipe2(
A.MakeBy(3, idxToFilename),
R.TraverseArray(F.Flow3(
file.ReadFile,
R.ChainEitherK(J.Unmarshal[RecordType]),
R.ChainFirstIOK(IO.Logf[RecordType]("Log Single: %v")),
)),
R.ChainFirstIOK(IO.Logf[[]RecordType]("Log Result: %v")),
)
result := data(context.Background())
assert.Equal(t, E.Of[error](A.From(RecordType{"file1"}, RecordType{"file2"}, RecordType{"file3"})), result())
}