gofp

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

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

Go to latest
Published: Aug 24, 2024 License: MIT Imports: 0 Imported by: 0

README

Functional programming library for golang

Features

  • Map
  • Filter
  • Reduce
  • Currying
  • Partial Application
  • Memorize
  • Monads
    • Try
    • Either
    • Option
    • IO

[!IMPORTANT] This is a work-in-progress library. The functionility and structure might change as it's being developed

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[I any](i []I, p Predicate[I]) []I

func Map

func Map[I, O any](i []I, f Function[I, O]) []O

func Reduce

func Reduce[T1, T2 any](i []T1, seed T2, acc Accumulator[T2, T1]) T2

Types

type Accumulator

type Accumulator[R, I any] func(R, I) R

type BindFn

type BindFn[T any] func(T) Monad[T]

type Either

type Either[R any] struct {
	Right R
	Left  error
}

TODO: Either[R, L any] for more generic options

func NewEither

func NewEither[R any](r R, l error) Either[R]

func (Either[R]) Bind

func (e Either[R]) Bind(b func(R) Either[R]) Either[R]

type Function

type Function[I, O any] func(I) O

type Maybe

type Maybe[T comparable] struct {
	Value T
}

func NewMaybe

func NewMaybe[T comparable](t T) Maybe[T]

func (Maybe[T]) Bind

func (m Maybe[T]) Bind(b BindFn[T]) Monad[T]

type Monad

type Monad[T any] interface {
	Bind(BindFn[T]) Monad[T]
}

type Predicate

type Predicate[T any] func(T) bool

type Try

type Try[T any] struct {
	Result T
	Err    error
}

TODO: Bind with Monad generic interface

func NewTry

func NewTry[T any](t T, err error) Try[T]

func (Try[T]) Bind

func (t Try[T]) Bind(b func(T) Try[T]) Try[T]

Jump to

Keyboard shortcuts

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