fun

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: BSD-2-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package fun provides reusable general-purpose functions (Const, Swap, Curry) and data structures (Unit, Either).

Index

Constants

This section is empty.

Variables

View Source
var Unit1 = Unit{}

Unit1 is the value of type Unit.

Functions

func Const

func Const[A any, B any](b B) func(A) B

Const creates a function that will ignore it's input and return the specified value.

func ConstUnit

func ConstUnit[B any](b B) func(Unit) B

ConstUnit creates a function that will ignore it's Unit input and return the specified value.

func Curry

func Curry[A any, B any, C any](f func(a A, b B) C) func(a A) func(b B) C

Curry takes a function that has two arguments and returns a function with two argument lists.

func Fold added in v0.0.10

func Fold[A any, B any, C any](eab Either[A, B], left func(A) C, right func(B) C) C

Fold pattern matches Either with two given pattern match handlers

func Identity added in v0.0.11

func Identity[A any](a A) A

Identity function returns the given value unchanged.

func IsLeft added in v0.0.10

func IsLeft[A any, B any](eab Either[A, B]) bool

IsLeft checks whether the provided Either is left or not.

func IsRight added in v0.0.10

func IsRight[A any, B any](eab Either[A, B]) bool

IsRight checks whether the provided Either is right or not.

func Swap

func Swap[A any, B any, C any](f func(a A) func(b B) C) func(b B) func(a A) C

Swap returns a curried function with swapped order of arguments.

Types

type Either added in v0.0.10

type Either[A any, B any] struct {
	IsLeft bool
	Left   A
	Right  B
}

Either is a simple data structure that can have either left value or right value.

func Left added in v0.0.10

func Left[A any, B any](a A) Either[A, B]

Left constructs Either that is left.

func Right[A any, B any](b B) Either[A, B]

Right constructs Either that is right.

type Pair added in v0.0.11

type Pair[A any, B any] struct {
	// contains filtered or unexported fields
}

Pair is a data structure that has two values.

func NewPair added in v0.0.11

func NewPair[A any, B any](a A, b B) Pair[A, B]

NewPair constructs the pair.

type Unit

type Unit struct{}

Unit is a type that has only a single value.

Jump to

Keyboard shortcuts

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