function

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply[A, B any](ab func(A) B, a A) B
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/function"
)

func main() {
	fmt.Println(function.Apply(
		func(x int) int {
			return x + 1
		},
		2,
	))

}
Output:

3

func Compose

func Compose[A, B, C any](bc func(B) C, ab func(A) B, a A) C
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/function"
)

func main() {
	fmt.Println(function.Compose(
		func(x int) string {
			return fmt.Sprint(x)
		},
		func(y float32) int {
			return int(y)
		},
		3.14,
	))

}
Output:

3

func Const

func Const[A, B any](a A, _ B) A
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/function"
)

func main() {
	fmt.Println(function.Const(1, true))

}
Output:

1

func Flip

func Flip[A, B, C any](abc func(A, B) C, b B, a A) C
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/function"
)

func main() {
	fmt.Println(function.Flip(
		func(a, b string) string {
			return a + " " + b
		},
		"world",
		"hello",
	))

}
Output:

hello world

func Id

func Id[A any](a A) A
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/function"
)

func main() {
	fmt.Println(function.Id(3))
	fmt.Println(function.Id("hello"))

}
Output:

3
hello

func On

func On[A, B, C any](b func(B, B) C, u func(A) B, x A, y A) C
Example
package main

import (
	"fmt"

	"github.com/calebcase/base/data/function"
)

func main() {
	v := function.On(
		func(a, b string) string {
			return a + b
		},
		func(x int) string {
			return fmt.Sprint(x)
		},
		4,
		2,
	)
	fmt.Printf("%v %T", v, v)

}
Output:

42 string

Types

This section is empty.

Jump to

Keyboard shortcuts

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