crawlerWPS / fgo

Functional GOlang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fgo

Functional GO!

cover

Features

  • Algebraic Data Types
    • Option
    • Result
    • Slice
    • HashMap
    • List
    • SkipList
    • Ref
    • Ptr
    • Lazy
    • Tuple
    • ...
  • Higher-Kinded Types
  • Typeclasses
    • Monoid
    • Functor
    • Eq
    • Ord
    • Iterable
    • Implement
    • Monad
    • Foldable
    • Enum
    • Apply
    • ...

Example

Monoid

type Monoid[A any] interface {
    Empty() A
    Combine(A, A) A
}

type foldExample[A any] struct {
    monoid Monoid[A]
}

func (example foldExample[A]) foldl(xs []A, acc func([]A, A) []A) []A {
    m := example.monoid
    ans := m.Empty()
    for _, x := range xs {
        ans = m.Combine(ans, x)
    }
    return ans
}

Functor

type Functor[F_, A, B any] interface {
    Fmap(types.HKT[F_, A], func(A) B) types.HKT[F_, B]
}

About

Functional GOlang

License:MIT License


Languages

Language:Go 100.0%