partial

package
v2.10.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package partial provides helpers for partial function application.

Each function in this package has a suffix for arity that indicates the number of arguments of the provided input function f.

Each Left/Right function returns a function with a single argument that can be used to "partially apply" input function f with one argument already bound.

Functions have the prefix "Left" if they bind the left-most argument first, or "Right" if they bind the right-most argument first.

Each input function must return exactly one value. The "fun/result" and "fun/maybe" packages provide useful functions that can wrap functions that return (value, ok) or (value, error) result types into single-value return variants.

For example,

f(a, b, c) => x becomes g(b, c) => x, with a bound, by calling Left3(f)(a).

f(a, b, c) => x becomes g(a, b) => x, with c bound, by calling Right3(f)(c).

f(a, b, c) => x becomes g() => x, with a, b, and c bound, by calling All3(f)(a, b, c).

f(a) => x becomes g() => x, with a bound, by calling Single(f)(a).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All2 added in v2.10.0

func All2[A any, B any, Return any](
	f func(A, B) Return,
) func(A, B) func() Return

func All3 added in v2.10.0

func All3[A any, B any, C any, Return any](
	f func(A, B, C) Return,
) func(A, B, C) func() Return

func All4 added in v2.10.0

func All4[A any, B any, C any, D any, Return any](
	f func(A, B, C, D) Return,
) func(A, B, C, D) func() Return

func Left2

func Left2[A any, B any, Return any](
	f func(a A, b B) Return,
) func(a A) func(b B) Return

func Left3

func Left3[A any, B any, C any, Return any](
	f func(a A, b B, c C) Return,
) func(a A) func(b B, c C) Return

func Left4

func Left4[A any, B any, C any, D any, Return any](
	f func(a A, b B, c C, d D) Return,
) func(a A) func(b B, c C, d D) Return

func Right2

func Right2[A any, B any, Return any](
	f func(a A, b B) Return,
) func(b B) func(a A) Return

func Right3

func Right3[A any, B any, C any, Return any](
	f func(a A, b B, c C) Return,
) func(c C) func(a A, b B) Return

func Right4

func Right4[A any, B any, C any, D any, Return any](
	f func(a A, b B, c C, d D) Return,
) func(d D) func(a A, b B, c C) Return

func Single added in v2.2.0

func Single[T any, Return any](
	f func(t T) Return,
) func(t T) func() Return

Single takes a function with a single argument and return value and constructs a function that takes a single argument and returns a function that takes no arguments and returns a single value.

For example,

opener :=  partial.Single(result.WrapFunc(os.Open))
fooOpener := opener("foo.txt")
f, err := fooOpener().Unpack()

Types

This section is empty.

Jump to

Keyboard shortcuts

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