Documentation
¶
Index ¶
- func Concat[A any, FA ..., MA monoid.Class[A], DA data.Data[A]](fa FA, ma MA, ta DA) A
- type Class
- type T
- type Type
- func (t Type[A, B]) Elem(ea eq.Class[A], a A, ta data.Data[A]) bool
- func (t Type[A, B]) Fold(ma monoid.Class[A], ta data.Data[A]) A
- func (t Type[A, B]) FoldL(f func(B, A) B, z B, ta data.Data[A]) B
- func (t Type[A, B]) FoldMap(mb monoid.Class[B], f func(A) B, ta data.Data[A]) B
- func (t Type[A, B]) FoldR(f func(A, B) B, z B, ta data.Data[A]) B
- func (t Type[A, B]) Length(ta data.Data[A]) int
- func (t Type[A, B]) Maximum(oa ord.Class[A], ta data.Data[A]) A
- func (t Type[A, B]) Minimum(oa ord.Class[A], ta data.Data[A]) A
- func (t Type[A, B]) Null(ta data.Data[A]) bool
- func (t Type[A, B]) ToList(ta data.Data[A]) (result []A)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Concat ¶ added in v0.0.9
func Concat[ A any, FA Class[ A, A, monoid.Class[A], monoid.Class[A], eq.Class[A], ord.Class[A], data.Data[A], ], MA monoid.Class[A], DA data.Data[A], ](fa FA, ma MA, ta DA) A
Example (Either) ¶
package main import ( "fmt" "github.com/calebcase/base/data/either" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[list.List[int], list.List[int]]() ll := either.Left[list.List[int], list.List[int]]{ Value: list.List[int]{42}, } lt := list.NewType[int]() // FIXME: This should return empty list, but instead it returns the // same as Right. fmt.Println(foldable.Concat[list.List[int]](t, lt, ll)) }
Output: []
Example (Listlist) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[list.List[int], list.List[int]]() ll := list.List[list.List[int]]{ {1, 2, 3}, {4, 5}, {6}, {}, } lt := list.NewType[int]() fmt.Println(foldable.Concat[list.List[int]](t, lt, ll)) }
Output: [1 2 3 4 5 6]
Example (Maybe) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" "github.com/calebcase/base/data/maybe" ) func main() { t := foldable.NewType[list.List[int], list.List[int]]() jl := maybe.Just[list.List[int]]{ Value: list.List[int]{1, 2, 3}, } lt := list.NewType[int]() fmt.Println(foldable.Concat[list.List[int]](t, lt, jl)) }
Output: [1 2 3]
Types ¶
type Class ¶
type Class[ A any, B any, MA monoid.Class[A], MB monoid.Class[B], EA eq.Class[A], OA ord.Class[A], TA T[A], ] interface { Fold(MA, TA) A FoldMap(MB, func(A) B, TA) B FoldR(func(A, B) B, B, TA) B FoldL(func(B, A) B, B, TA) B ToList(TA) []A Null(TA) bool Length(TA) int Elem(EA, A, TA) bool Maximum(OA, TA) A Minimum(OA, TA) A }
type Type ¶
func (Type[A, B]) Elem ¶ added in v0.0.6
Example (Int) ¶
package main import ( "fmt" "github.com/calebcase/base/data/eq" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[int, int]() l := list.List[int]{1, 2, 3} e := eq.NewType(eq.Comparable[int]) fmt.Println(t.Elem(e, 2, l)) fmt.Println(t.Elem(e, 10, l)) }
Output: true false
Example (String) ¶
package main import ( "fmt" "github.com/calebcase/base/data/eq" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[string, string]() l := list.List[string]{ "a", "needle", "in", "a", "haystack", } e := eq.NewType(eq.Comparable[string]) fmt.Println(t.Elem(e, "needle", l)) fmt.Println(t.Elem(e, "gold", l)) }
Output: true false
func (Type[A, B]) Fold ¶
Example ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[list.List[int], list.List[int]]() ll := list.List[list.List[int]]{ {1, 2, 3}, {4, 5}, {6}, {}, } lt := list.NewType[int]() fmt.Println(t.Fold(lt, ll)) }
Output: [1 2 3 4 5 6]
func (Type[A, B]) FoldL ¶
Example ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[int, string]() l := list.List[int]{1, 2, 3} comma := func(acc string, x int) string { if acc == "" { return fmt.Sprint(x) } return acc + ", " + fmt.Sprint(x) } fmt.Println(t.FoldL(comma, "", l)) }
Output: 1, 2, 3
func (Type[A, B]) FoldMap ¶
Example ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/function" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[list.List[int], list.List[int]]() ll := list.List[list.List[int]]{ {1, 2, 3}, {4, 5}, {6}, {}, } lt := list.NewType[int]() fmt.Println(t.FoldMap(lt, function.Id[list.List[int]], ll)) }
Output: [1 2 3 4 5 6]
func (Type[A, B]) FoldR ¶
Example ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[int, int]() l := list.List[int]{1, 2, 3} sum := func(acc, x int) int { return acc + x } fmt.Println(t.FoldR(sum, 0, l)) }
Output: 6
func (Type[A, B]) Length ¶ added in v0.0.6
Example (List) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[int, int]() fmt.Println(t.Length(list.List[int]{1, 2, 3})) fmt.Println(t.Length(list.List[int]{})) }
Output: 3 0
Example (Maybe) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/maybe" ) func main() { t := foldable.NewType[int, int]() fmt.Println(t.Length(maybe.Just[int]{Value: 2})) fmt.Println(t.Length(maybe.Nothing[int]{})) }
Output: 1 0
func (Type[A, B]) Maximum ¶ added in v0.0.6
Example (Int) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" "github.com/calebcase/base/data/ord" ) func main() { t := foldable.NewType[int, int]() l := list.List[int]{1, 2, 3} o := ord.NewType(ord.Ordered[int]) fmt.Println(t.Maximum(o, l)) }
Output: 3
Example (String) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" "github.com/calebcase/base/data/ord" ) func main() { t := foldable.NewType[string, string]() l := list.List[string]{"a", "b", "c"} o := ord.NewType(ord.Ordered[string]) fmt.Println(t.Maximum(o, l)) }
Output: c
func (Type[A, B]) Minimum ¶ added in v0.0.6
Example (Int) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" "github.com/calebcase/base/data/ord" ) func main() { t := foldable.NewType[int, int]() l := list.List[int]{1, 2, 3} o := ord.NewType(ord.Ordered[int]) fmt.Println(t.Minimum(o, l)) }
Output: 1
Example (String) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" "github.com/calebcase/base/data/ord" ) func main() { t := foldable.NewType[string, string]() l := list.List[string]{"a", "b", "c"} o := ord.NewType(ord.Ordered[string]) fmt.Println(t.Minimum(o, l)) }
Output: a
func (Type[A, B]) Null ¶ added in v0.0.6
Example (List) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/list" ) func main() { t := foldable.NewType[int, int]() fmt.Println(t.Null(list.List[int]{1, 2, 3})) fmt.Println(t.Null(list.List[int]{})) }
Output: false true
Example (Maybe) ¶
package main import ( "fmt" "github.com/calebcase/base/data/foldable" "github.com/calebcase/base/data/maybe" ) func main() { t := foldable.NewType[int, int]() fmt.Println(t.Null(maybe.Just[int]{Value: 2})) fmt.Println(t.Null(maybe.Nothing[int]{})) }
Output: false true
Click to show internal directories.
Click to hide internal directories.