Help us shape the future of Go! Take the 2026 Go Developer Survey

file

package
v1.1.79 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

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 Close

func Close[C io.Closer](c C) RIOE.ReaderIOEither[any]

Close closes an object

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[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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL