pkg

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OrderingLessThan    = "OrderingLessThan"
	OrderingEqual       = "OrderingEqual"
	OrderingGreaterThan = "OrderingGreaterThan"
)

Variables

View Source
var UnitC = &Unit{}

Functions

func AllSlice added in v0.0.2

func AllSlice[A any](f F1[A, bool], xs []A) bool

func And added in v0.0.2

func And(a bool, b bool) bool

func AnySlice added in v0.0.2

func AnySlice[A any](f F1[A, bool], xs []A) bool

func Apply

func Apply[A, B any](f F1[A, B], x A) B

func ConcatSlice added in v0.0.2

func ConcatSlice[A any](xs []A, ys []A) []A

func ConcatSlices added in v0.0.2

func ConcatSlices[A any](xss [][]A) []A

func Divide added in v0.0.2

func Divide[T Number](a T, b T) T

func Equal added in v0.0.7

func Equal[T Eq[T]](a T, b T) bool

func EqualPair added in v0.0.7

func EqualPair[A Eq[A], B Eq[B]](p1 *Pair[A, B], p2 *Pair[A, B]) bool

func FilterSlice

func FilterSlice[A any](f F1[A, bool], xs []A) []A

func First

func First[A, B any](p *Pair[A, B]) A

func GreaterThan

func GreaterThan[T Ord[T]](a T, b T) bool

func GreaterThanOrEqual

func GreaterThanOrEqual[T Ord[T]](a T, b T) bool

func GroupSlice added in v0.0.2

func GroupSlice[A EqOrComparable[A]](xs []A) map[A][]A

func Id

func Id[A any](x A) A

func Index

func Index[T Eq[T]](s []T, e T) int

func Intercalate added in v0.0.2

func Intercalate[A any](sep []A, xss [][]A) []A

func Intersperse added in v0.0.2

func Intersperse[A any](sep A, xs []A) []A

func IsEmptySlice added in v0.0.2

func IsEmptySlice[A any](xs []A) bool

func LessThan

func LessThan[T Ord[T]](a T, b T) bool

func LessThanOrEqual

func LessThanOrEqual[T Ord[T]](a T, b T) bool

func MapMap added in v0.0.2

func MapMap[A comparable, B, C any](f F1[B, C], kvs map[A]B) map[A]C

func MapSlice

func MapSlice[A, B any](f F1[A, B], xs []A) []B

func Max

func Max[T Ord[T]](a T, b T) T

func Merge

func Merge[A any](xs []A, ys []A, compare func(A, A) Ordering) []A

Merge ...

func MergeSortWithComparator

func MergeSortWithComparator[A any](xs []A, compare func(A, A) Ordering) []A

MergeSortWithComparator needs to be rewritten iteratively TODO

func Min

func Min[T Ord[T]](a T, b T) T

func Minus added in v0.0.2

func Minus[T Number](a T, b T) T

func NotEqual added in v0.0.2

func NotEqual[T Eq[T]](a T, b T) bool

func Or added in v0.0.2

func Or(a bool, b bool) bool

func PartitionSlice added in v0.0.2

func PartitionSlice[A any](predicate F1[A, bool], xs []A) ([]A, []A)

func Plus added in v0.0.2

func Plus[T Number](a T, b T) T

func ProductSlice added in v0.0.2

func ProductSlice[A Number](xs []A) A

func ReduceMaybe

func ReduceMaybe[A, B any](m *Maybe[A], b B, f F2[B, A, B]) B

func ReduceSlice

func ReduceSlice[A, B any](f F2[B, A, B], b B, xs []A) B

func Replicate

func Replicate[A any](count int, item A) []A

Replicate should be written using unfold or something

func ReverseSlice added in v0.0.2

func ReverseSlice[A any](xs []A) []A

func Second

func Second[A, B any](p *Pair[A, B]) B

func Sort added in v0.0.3

func Sort[A Ord[A]](xs []A) []A

Sort orders elements by their natural Ord instance.

func SortBy added in v0.0.3

func SortBy[A any](xs []A, compare F2[A, A, Ordering]) []A

SortBy allows sorting based on a custom comparison operator;

therefore it does not require input elements to have an Ord instance.
See https://hackage.haskell.org/package/base-4.16.2.0/docs/Data-List.html#v:sortBy

func SortOn added in v0.0.3

func SortOn[A any, B Ord[B]](xs []A, projection F1[A, B]) []A

SortOn is based on a Haskell function and the decorate/sort/undecorate pattern.

It allows a projection of each element to be used to determine the order.
The projection must have an Ord instance.
https://hackage.haskell.org/package/base-4.16.2.0/docs/Data-List.html#v:sortOn

func SortOnBy added in v0.0.8

func SortOnBy[A any, B any](xs []A, projection F1[A, B], compare F2[B, B, Ordering]) []A

SortOnBy combines the functionality of `SortOn` and `SortBy`,

thereby separating projection and comparison functions

func SumSlice added in v0.0.2

func SumSlice[A Number](xs []A) A

func Times added in v0.0.2

func Times[T Number](a T, b T) T

func UnfoldrSlice added in v0.0.2

func UnfoldrSlice[A, B any](f F1[B, *Maybe[*Pair[A, B]]], b B) []A

func UnwrapBool added in v0.0.7

func UnwrapBool(a Bool) bool

func UnwrapComplex128 added in v0.0.7

func UnwrapComplex128(a Complex128) complex128

func UnwrapComplex64 added in v0.0.7

func UnwrapComplex64(a Complex64) complex64

func UnwrapFloat32 added in v0.0.7

func UnwrapFloat32(a Float32) float32

func UnwrapFloat64 added in v0.0.7

func UnwrapFloat64(a Float64) float64

func UnwrapInt added in v0.0.7

func UnwrapInt(a Int) int

func UnwrapInt16 added in v0.0.7

func UnwrapInt16(a Int16) int16

func UnwrapInt32 added in v0.0.7

func UnwrapInt32(a Int32) int32

func UnwrapInt64 added in v0.0.7

func UnwrapInt64(a Int64) int64

func UnwrapInt8 added in v0.0.7

func UnwrapInt8(a Int8) int8

func UnwrapString added in v0.0.7

func UnwrapString(a String) string

func UnwrapUint added in v0.0.7

func UnwrapUint(a Uint) uint

func UnwrapUint16 added in v0.0.7

func UnwrapUint16(a Uint16) uint16

func UnwrapUint32 added in v0.0.7

func UnwrapUint32(a Uint32) uint32

func UnwrapUint64 added in v0.0.7

func UnwrapUint64(a Uint64) uint64

func UnwrapUint8 added in v0.0.7

func UnwrapUint8(a Uint8) uint8

func UnwrapUintptr added in v0.0.7

func UnwrapUintptr(a Uintptr) uintptr

Types

type Bool

type Bool bool

func WrapBool added in v0.0.7

func WrapBool(a bool) Bool

func (Bool) Compare

func (a Bool) Compare(b Bool) Ordering

func (Bool) Equal

func (a Bool) Equal(b Bool) bool

type Complex128

type Complex128 complex128

func WrapComplex128 added in v0.0.7

func WrapComplex128(a complex128) Complex128

func (Complex128) Equal

func (a Complex128) Equal(b Complex128) bool

type Complex64

type Complex64 complex64

func WrapComplex64 added in v0.0.7

func WrapComplex64(a complex64) Complex64

func (Complex64) Equal

func (a Complex64) Equal(b Complex64) bool

type Either added in v0.0.2

type Either[E any, A any] struct {
	Success *A
	Error   *E
}

func App2 added in v0.0.2

func App2[E, A, B, C any](f func(A, B) C, m1 *Either[E, A], m2 *Either[E, B]) *Either[E, C]

func Bind added in v0.0.2

func Bind[E, A, B any](m *Either[E, A], f func(A) *Either[E, B]) *Either[E, B]

func Fmap added in v0.0.2

func Fmap[E, A, B any](m *Either[E, A], f func(a A) B) *Either[E, B]

func MapError added in v0.0.2

func MapError[E1, E2, A any](m *Either[E1, A], f func(E1) E2) *Either[E2, A]

func NewError added in v0.0.2

func NewError[E any, A any](error E) *Either[E, A]

func NewSuccess added in v0.0.2

func NewSuccess[E any, A any](value A) *Either[E, A]

func (*Either[E, A]) IsValid added in v0.0.2

func (e *Either[E, A]) IsValid() bool

IsValid is a debugging check

func (*Either[E, A]) Plus added in v0.0.2

func (e *Either[E, A]) Plus(other *Either[E, A]) *Either[E, A]

type Eq

type Eq[T any] interface {
	Equal(T) bool
}

type EqOrComparable

type EqOrComparable[A Eq[A]] interface {
	Eq[A]
	comparable
}

EqOrComparable allows us to avoid getting "invalid map key type A (missing comparable constraint)"

errors, if we just used Eq[A] without this additional interface

type F1

type F1[A, Z any] func(A) Z

func Compose

func Compose[A, B, C any](f F1[B, C], g F1[A, B]) F1[A, C]

func Const

func Const[A, B any](x A) F1[B, A]

func Partial2

func Partial2[A, B, Z any](f F2[A, B, Z]) F1[A, F1[B, Z]]

func Partial3 added in v0.0.2

func Partial3[A, B, C, Z any](f F3[A, B, C, Z]) F1[A, F1[B, F1[C, Z]]]

func Partial4 added in v0.0.2

func Partial4[A, B, C, D, Z any](f F4[A, B, C, D, Z]) F1[A, F1[B, F1[C, F1[D, Z]]]]

type F2

type F2[A, B, Z any] func(A, B) Z

func ComparingP added in v0.0.3

func ComparingP[A any, B Ord[B]](f F1[A, B]) F2[A, A, Ordering]

ComparingP is a partial application of Comparing, fixing the first argument

func Flip

func Flip[A, B, C any](f F2[A, B, C]) F2[B, A, C]

type F3

type F3[A, B, C, Z any] func(A, B, C) Z

type F4

type F4[A, B, C, D, Z any] func(A, B, C, D) Z

type F5

type F5[A, B, C, D, E, Z any] func(A, B, C, D, E) Z

type Float32

type Float32 float32

func WrapFloat32 added in v0.0.7

func WrapFloat32(a float32) Float32

func (Float32) Compare

func (a Float32) Compare(b Float32) Ordering

func (Float32) Equal

func (a Float32) Equal(b Float32) bool

type Float64

type Float64 float64

func WrapFloat64 added in v0.0.7

func WrapFloat64(a float64) Float64

func (Float64) Compare

func (a Float64) Compare(b Float64) Ordering

func (Float64) Equal

func (a Float64) Equal(b Float64) bool

type Int

type Int int

func WrapInt added in v0.0.7

func WrapInt(a int) Int

func (Int) Compare

func (a Int) Compare(b Int) Ordering

func (Int) Equal

func (a Int) Equal(b Int) bool

type Int16

type Int16 int16

func WrapInt16 added in v0.0.7

func WrapInt16(a int16) Int16

func (Int16) Compare

func (a Int16) Compare(b Int16) Ordering

func (Int16) Equal

func (a Int16) Equal(b Int16) bool

type Int32

type Int32 int32

func WrapInt32 added in v0.0.7

func WrapInt32(a int32) Int32

func (Int32) Compare

func (a Int32) Compare(b Int32) Ordering

func (Int32) Equal

func (a Int32) Equal(b Int32) bool

type Int64

type Int64 int64

func WrapInt64 added in v0.0.7

func WrapInt64(a int64) Int64

func (Int64) Compare

func (a Int64) Compare(b Int64) Ordering

func (Int64) Equal

func (a Int64) Equal(b Int64) bool

type Int8

type Int8 int8

func WrapInt8 added in v0.0.7

func WrapInt8(a int8) Int8

func (Int8) Compare

func (a Int8) Compare(b Int8) Ordering

func (Int8) Equal

func (a Int8) Equal(b Int8) bool

type List

type List[A any] struct {
	Head A
	Tail *List[A] // TODO use maybe
}

func NewList

func NewList[A any](xs []A) *List[A]

type MapEq

type MapEq[A EqOrComparable[A], B Eq[B]] map[A]B

func (MapEq[A, B]) Equal

func (xs MapEq[A, B]) Equal(ys MapEq[A, B]) bool

type Maybe

type Maybe[A any] struct {
	Value *A
}

func BindMaybe

func BindMaybe[A, B any](m *Maybe[A], f F1[A, *Maybe[B]]) *Maybe[B]

func FilterMaybe

func FilterMaybe[A any](m *Maybe[A], f F1[A, bool]) *Maybe[A]

func Just

func Just[A any](a A) *Maybe[A]

func MapMaybe

func MapMaybe[A, B any](f F1[A, B], m *Maybe[A]) *Maybe[B]

func Nothing

func Nothing[A any]() *Maybe[A]

func (*Maybe[A]) Default added in v0.0.2

func (m *Maybe[A]) Default(defaultValue A) A

type Number added in v0.0.2

type Number interface {
	constraints.Integer | constraints.Float
}

Number is built out of:

https://pkg.go.dev/golang.org/x/exp@v0.0.0-20220706164943-b4a6d9510983/constraints

type Ord

type Ord[T any] interface {
	Eq[T]
	Compare(T) Ordering
}

type Ordering

type Ordering string

func Compare added in v0.0.3

func Compare[A Ord[A]](x A, y A) Ordering

func Comparing added in v0.0.3

func Comparing[A any, B Ord[B]](f F1[A, B], x A, y A) Ordering

type Pair

type Pair[A, B any] struct {
	Fst A
	Snd B
}

func NewPair

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

func Zip added in v0.0.2

func Zip[A, B any](xs []A, ys []B) []*Pair[A, B]

type PairEq added in v0.0.7

type PairEq[A Eq[A], B Eq[B]] Pair[A, B]

func (PairEq[A, B]) Equal added in v0.0.7

func (p1 PairEq[A, B]) Equal(p2 PairEq[A, B]) bool

type PairOrd added in v0.0.8

type PairOrd[A Ord[A], B Ord[B]] Pair[A, B]

func (PairOrd[A, B]) Compare added in v0.0.8

func (p1 PairOrd[A, B]) Compare(p2 PairOrd[A, B]) Ordering

func (PairOrd[A, B]) Equal added in v0.0.8

func (p1 PairOrd[A, B]) Equal(p2 PairOrd[A, B]) bool

type Set added in v0.0.2

type Set[T EqOrComparable[T]] struct {
	Elems map[T]bool
}

func NewSet added in v0.0.2

func NewSet[T EqOrComparable[T]](elems []T) *Set[T]

func (*Set[T]) Add added in v0.0.2

func (s *Set[T]) Add(a T)

func (*Set[T]) Contains added in v0.0.2

func (s *Set[T]) Contains(a T) bool

func (*Set[T]) Delete added in v0.0.2

func (s *Set[T]) Delete(a T)

func (*Set[T]) Len added in v0.0.2

func (s *Set[T]) Len() int

func (*Set[T]) ToSlice added in v0.0.2

func (s *Set[T]) ToSlice() []T

type SliceEq

type SliceEq[A Eq[A]] []A

func (SliceEq[A]) Equal

func (xs SliceEq[A]) Equal(ys SliceEq[A]) bool

type SliceOrd

type SliceOrd[A Ord[A]] []A

func (SliceOrd[A]) Compare

func (xs SliceOrd[A]) Compare(ys SliceOrd[A]) Ordering

Compare should work like in Haskell. Examples from Haskell:

Prelude> [1,2,3] < [3,4,5]
True
Prelude> [1,2,3] < [3,4]
True
Prelude> [1,2,3] < []
False

func (SliceOrd[A]) Equal added in v0.0.6

func (xs SliceOrd[A]) Equal(ys SliceOrd[A]) bool

func (SliceOrd[A]) Sort

func (xs SliceOrd[A]) Sort() SliceOrd[A]

type String

type String string

func WrapString added in v0.0.7

func WrapString(a string) String

func (String) Compare

func (a String) Compare(b String) Ordering

func (String) Equal

func (a String) Equal(b String) bool

type Uint

type Uint uint

func WrapUint added in v0.0.7

func WrapUint(a uint) Uint

func (Uint) Compare

func (a Uint) Compare(b Uint) Ordering

func (Uint) Equal

func (a Uint) Equal(b Uint) bool

type Uint16

type Uint16 uint16

func WrapUint16 added in v0.0.7

func WrapUint16(a uint16) Uint16

func (Uint16) Compare

func (a Uint16) Compare(b Uint16) Ordering

func (Uint16) Equal

func (a Uint16) Equal(b Uint16) bool

type Uint32

type Uint32 uint32

func WrapUint32 added in v0.0.7

func WrapUint32(a uint32) Uint32

func (Uint32) Compare

func (a Uint32) Compare(b Uint32) Ordering

func (Uint32) Equal

func (a Uint32) Equal(b Uint32) bool

type Uint64

type Uint64 uint64

func WrapUint64 added in v0.0.7

func WrapUint64(a uint64) Uint64

func (Uint64) Compare

func (a Uint64) Compare(b Uint64) Ordering

func (Uint64) Equal

func (a Uint64) Equal(b Uint64) bool

type Uint8

type Uint8 uint8

func WrapUint8 added in v0.0.7

func WrapUint8(a uint8) Uint8

func (Uint8) Compare

func (a Uint8) Compare(b Uint8) Ordering

func (Uint8) Equal

func (a Uint8) Equal(b Uint8) bool

type Uintptr added in v0.0.2

type Uintptr uintptr

func WrapUintptr added in v0.0.7

func WrapUintptr(a uintptr) Uintptr

func (Uintptr) Compare added in v0.0.2

func (a Uintptr) Compare(b Uintptr) Ordering

func (Uintptr) Equal added in v0.0.2

func (a Uintptr) Equal(b Uintptr) bool

type Unit

type Unit struct{}

Unit represents the Haskell value `()`

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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