Documentation
¶
Index ¶
- Variables
- func Close[C io.Closer](c C) RIOE.ReaderIOEither[any]
- func CreateTemp(dir, pattern string) RIOE.ReaderIOEither[*os.File]
- func ReadFile(path string) RIOE.ReaderIOEither[[]byte]
- func WithTempFile[A any](f func(*os.File) RIOE.ReaderIOEither[A]) RIOE.ReaderIOEither[A]
- func Write[R any, W io.WriteCloser](acquire RIOE.ReaderIOEither[W]) func(use func(W) RIOE.ReaderIOEither[R]) RIOE.ReaderIOEither[R]
- func WriteAll[W io.WriteCloser](data []byte) func(acquire RIOE.ReaderIOEither[W]) RIOE.ReaderIOEither[[]byte]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // Open opens a file for reading within the given context Open = F.Flow3( IOEF.Open, RIOE.FromIOEither[*os.File], RIOE.WithContext[*os.File], ) // Remove removes a file by name Remove = F.Flow2( IOEF.Remove, RIOE.FromIOEither[string], ) )
Functions ¶
func CreateTemp ¶ added in v1.0.34
func CreateTemp(dir, pattern string) RIOE.ReaderIOEither[*os.File]
CreateTemp created a temp file with proper parametrization
func ReadFile ¶
func ReadFile(path string) RIOE.ReaderIOEither[[]byte]
ReadFile reads a file in the scope of a context
Example ¶
package main import ( "context" "fmt" R "github.com/IBM/fp-go/context/readerioeither" F "github.com/IBM/fp-go/function" IO "github.com/IBM/fp-go/io" J "github.com/IBM/fp-go/json" ) type RecordType struct { Data string `json:"data"` } func getData(r RecordType) string { return r.Data } func main() { data := F.Pipe3( ReadFile("./data/file.json"), R.ChainEitherK(J.Unmarshal[RecordType]), R.ChainFirstIOK(IO.Logf[RecordType]("Log: %v")), R.Map(getData), ) result := data(context.Background()) fmt.Println(result()) }
Output: Right[<nil>, string](Carsten)
func WithTempFile ¶ added in v1.0.34
func WithTempFile[A any](f func(*os.File) RIOE.ReaderIOEither[A]) RIOE.ReaderIOEither[A]
WithTempFile creates a temporary file, then invokes a callback to create a resource based on the file, then close and remove the temp file
func Write ¶ added in v1.0.35
func Write[R any, W io.WriteCloser](acquire RIOE.ReaderIOEither[W]) func(use func(W) RIOE.ReaderIOEither[R]) RIOE.ReaderIOEither[R]
Write uses a generator function to create a stream, writes data to it and closes it
func WriteAll ¶ added in v1.0.35
func WriteAll[W io.WriteCloser](data []byte) func(acquire RIOE.ReaderIOEither[W]) RIOE.ReaderIOEither[[]byte]
WriteAll uses a generator function to create a stream, writes data to it and closes it
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.