result

package
v0.0.0-...-1f40f5c Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result[T, E any] struct {
	// contains filtered or unexported fields
}

func Error

func Error[T, E any](err E) Result[T, E]

func Map

func Map[T, E, U any](r Result[T, E], op func(T) U) Result[U, E]
Example
package main

import (
	"fmt"

	"codeberg.org/FedericoSchonborn/go-sandbox/result"
	"codeberg.org/FedericoSchonborn/go-sandbox/result/strconv"
)

func main() {
	value := result.Map(strconv.Atoi("2"), func(i int) int {
		return i * 2
	})
	fmt.Println(value)

}
Output:

Ok(4)

func Ok

func Ok[T, E any](value T) Result[T, E]

func Try

func Try[T any, E error](value T, err E) Result[T, E]
Example
package main

import (
	"fmt"
	"time"

	"codeberg.org/FedericoSchonborn/go-sandbox/result"
)

func main() {
	value := result.Try(time.LoadLocation("Local"))
	fmt.Println(value)

}
Output:

Ok(Local)

func (Result[T, E]) Format

func (r Result[T, E]) Format(f fmt.State, verb rune)

func (Result[T, E]) IsError

func (r Result[T, E]) IsError() bool

func (Result[T, E]) IsOk

func (r Result[T, E]) IsOk() bool

func (Result[T, E]) Match

func (r Result[T, E]) Match(onOk func(T), onError func(E))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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