functional

package module
v0.0.0-...-d4b0244 Latest Latest
Warning

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

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

README

functional-go

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FoldLeft

func FoldLeft[FA Foldable[A], A any, B any](foldable FA, initial B, foldFn func(elem A, state B) B) B

Types

type FoldLeftFn

type FoldLeftFn[A any] interface {
	Next(elem A)
}

type Foldable

type Foldable[A any] interface {
	FoldLeft(fn FoldLeftFn[A])
}

type Monoid

type Monoid[A any] interface {
	Semigroup[A]
	Empty() A
}

type Semigroup

type Semigroup[A any] interface {
	Combine(x A, y A) A
}

type Slice

type Slice[A any] []A

func (Slice[A]) FoldLeft

func (s Slice[A]) FoldLeft(fn FoldLeftFn[A])
Example
s := Slice[int]{1, 2, 3, 4}
r := FoldLeft(s, 10, func(elem int, state int) int {
	fmt.Println(elem, state)
	return elem + state
})
fmt.Println("=", r)
Output:

1 10
2 11
3 13
4 16
= 20

Directories

Path Synopsis
monads
rx
types
typelists
Package typelists allows representing list of types on the type level.
Package typelists allows representing list of types on the type level.

Jump to

Keyboard shortcuts

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