Skip to content

Commit

Permalink
add kleisili composition
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Skinner committed Nov 30, 2016
1 parent f0d588c commit 07ccbba
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions monad/monad.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ type Monad interface {
Return(i interface{}) Monad
}

// MPlus defines the interface for the MonadPlus class
type MPlus interface {
Monad
MZero() Monad
}

// FMap applies a function inside of a monadic value
func FMap(f func(interface{}) interface{}, m Monad) Monad {
fmap := func(i interface{}) Monad {
Expand All @@ -36,3 +42,8 @@ func FMap(f func(interface{}) interface{}, m Monad) Monad {
func Join(m Monad) Monad {
return m.AndThen(func(i interface{}) Monad { return i.(Monad) })
}

// Kleisli composition for monadic functions
func Kleisli(a, b func(i interface{}) Monad) func(i interface{}) Monad {
return func(i interface{}) Monad { return b(i).AndThen(a) }
}

0 comments on commit 07ccbba

Please sign in to comment.