pkg

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: MIT Imports: 3 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 EqExample

func EqExample()

func Example

func Example()

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, f func(A, A) Ordering) []A

Merge ...

func MergeSortWithComparator

func MergeSortWithComparator[A any](xs []A, f 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

func SortBy added in v0.0.3

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

func SortOn added in v0.0.3

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

SortOn has a TODO: it needs to be efficiently implemented

example: https://hackage.haskell.org/package/base-4.16.2.0/docs/src/Data.OldList.html#sortOn
to avoid calling f multiple times

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

Types

type Bool

type 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 (Complex128) Equal

func (a Complex128) Equal(b Complex128) bool

type Complex64

type 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 Ord[A], B any](f F1[B, A]) F2[B, B, 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 (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 (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 (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 (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 (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 (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 (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]](y A, z A) Ordering

func Comparing added in v0.0.3

func Comparing[A Ord[A], B any](f F1[B, A], x B, y B) 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 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]) Sort

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

type String

type 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 (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 (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 (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 (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 (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 (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