funky

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package funky provides a few constructs usually present in pure functional programming environments, using Go 1.18 generics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapSlice

func MapSlice[V, W any](in slice[V], f func(V) W) slice[W]

func Mapping

func Mapping[K comparable, V any](m map[K]V) mapping[K, V]

func MappingFromSlice

func MappingFromSlice[K comparable, V any](sl slice[MapItem[K, V]]) mapping[K, V]

func Slice

func Slice[V any](sl []V) slice[V]

func SliceIterator

func SliceIterator[V any](sl slice[V]) *sliceIterator[V]

func ToSlice

func ToSlice[V any](it Iterator[V]) slice[V]

func Walk

func Walk[V any](it Iterator[V], f func(V))

Walk may be used as a default implementation for the Iterator.Walk() method.

Types

type Either

type Either[E, V any] interface {
	Maybe[V]
	IsLeft() bool
	IsRight() bool
	Left() E
	Right() V
}

An Either item has either a Left value (signifying some special condition like an error) or a Right (real) one. It also provides the Maybe interface, interpreting a Left value as Nothing.

func Left

func Left[E, V any](e E) Either[E, V]

func MapEither

func MapEither[E, V, W any](in Either[E, V], f func(V) W) Either[E, W]
func Right[E, V any](v V) Either[E, V]

type Iterable

type Iterable[V any] interface {
	Iterator() Iterator[V]
}

type Iterator

type Iterator[V any] interface {
	Maybe[V]
	Next() bool
	Value() V
	Walk(func(V))
}

func MapIterator

func MapIterator[In, Out any](itin Iterator[In], f func(In) Out) Iterator[Out]

func MappingIterator

func MappingIterator[K comparable, V any](m mapping[K, V]) Iterator[MapItem[K, V]]

type Map

type Map[K comparable, V any] interface {
	Iterable[MapItem[K, V]]
	Maybe[MapItem[K, V]]
	Sizeable
	Get(K) Maybe[V]
	Set(K, V)
	Delete(K)
	Keys() Iterator[K]
	Values() Iterator[V]
}

func MapMapping

func MapMapping[K comparable, V, W any](in Map[K, V], f func(V) W) Map[K, W]

type MapItem

type MapItem[K comparable, V any] struct {
	Key   K
	Value V
}

type Maybe

type Maybe[V any] interface {
	IsNothing() bool
	Value() V
}

A Maybe item may contain a real Value or Nothing.

func Just

func Just[V any](value V) Maybe[V]

func MapMaybe

func MapMaybe[V, W any](in Maybe[V], f func(V) W) Maybe[W]

func Nothing

func Nothing[V any]() Maybe[V]

type Sizeable

type Sizeable interface {
	Size() Maybe[int]
}

Jump to

Keyboard shortcuts

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