Skip to content

Instantly share code, notes, and snippets.

View philzook58's full-sized avatar

Philip Zucker philzook58

View GitHub Profile
@sjoerdvisscher
sjoerdvisscher / cont.swift
Last active January 10, 2021 14:36
The mother of all monads to the rescue
// See http://blog.sigfpe.com/2008/12/mother-of-all-monads.html
// MARK: function composition
infix operator >>> { associativity left }
func >>> <A, B, C>(f: A -> B, g: B -> C) -> A -> C {
return { x in g(f(x)) }
}
// MARK: Continuation monad
struct Cont<R, A> {