Skip to content

Instantly share code, notes, and snippets.

View telyn's full-sized avatar
🌈

Telyn telyn

🌈
View GitHub Profile
@telyn
telyn / chain.go
Last active April 15, 2024 06:42 — forked from anonymous/chain.go
Function chaining in go. It's essentially the same as the Either Monad - but a little less monad-y
package chain
import (
"fmt"
"reflect"
)
// Chain takes an array of functions, and calls them all, passing the result of the previous call to the next. Any funcs whose last return value is an error have the errors checked and not passed to the next. If an error occurs at any point chain returns with an empty list and the error that happened.
// here it is expressed vaguely maths-y which might be clearer.
// given a function f[n] which returns a set of values vs: