Created
November 28, 2022 03:06
-
-
Save danielt1263/d7d823470e5faa369163ee6ceadda1de to your computer and use it in GitHub Desktop.
A list of combinators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func apply<A, B>(fn: (A) -> B, a: A) -> B { | |
fn(a) | |
} | |
func bluebird<A, B, C>(fn1: (A) -> B, fn2: (C) -> A, c: C) -> B { | |
fn1(fn2(c)) | |
} | |
func blackbird<A, B, C, D>(fn1: (C) -> D, fn2: (A, B) -> C, a: A, b: B) -> D { | |
fn1(fn2(a, b)) | |
} | |
func cardinal<A, B, C>(fn: (A, B) -> C, b: B, a: A) -> C { | |
fn(a, b) | |
} | |
func dove<A, B, C, D>(fn1: (A, C) -> D, a: A, fn2: (B) -> C, b: B) -> D { | |
fn1(a, fn2(b)) | |
} | |
func finch<A, B, C>(a: A, b: B, fn: (B, A) -> C) -> C { | |
fn(b, a) | |
} | |
func goldfinch<A, B, C, D>(fn1: (A, B) -> C, fn2: (D) -> B, d: D, a: A) -> C { | |
fn1(a, fn2(d)) | |
} | |
func hummingbird<A, B, C>(fn: (A, B, A) -> C, a: A, b: B) -> C { | |
fn(a, b, a) | |
} | |
func jay<A, B>(fn1: (A, B) -> B, a1: A, b: B, a2: A) -> B { | |
fn1(a1, fn1(a2, b)) | |
} | |
func kestrel<A, B>(a: A, b: B) -> A { | |
a | |
} | |
func kite<A, B>(a: A, b: B) -> B { | |
b | |
} | |
func owl<A, B>(_ fn1: @escaping ((A) -> B) -> A, fn2: (A) -> B) -> B { | |
fn2(fn1(fn2)) | |
} | |
func phoenix<A, B, C, D>(fn1: (A, B) -> C, fn2: (D) -> A, fn3: (D) -> B, d: D) -> C { | |
fn1(fn2(d), fn3(d)) | |
} | |
func psi<A, B, C>(fn1: (A, A) -> B, fn2: (C) -> A, c1: C, c2: C) -> B { | |
fn1(fn2(c1), fn2(c2)) | |
} | |
func queer<A, B, C>(fn1: (A) -> B, fn2: (B) -> C, a: A) -> C { | |
fn2(fn1(a)) | |
} | |
func robin<A, B, C>(a: A, fn: (B, A) -> C, b: B) -> C { | |
fn(b, a) | |
} | |
func starling<A, B, C>(fn1: (A, B) -> C, fn2: (A) -> B, a: A) -> C { | |
fn1(a, fn2(a)) | |
} | |
func starling<A, B, C>(fn1: (A, B) -> C, fn2: (B) -> A, b: B) -> C { | |
fn1(fn2(b), b) | |
} | |
func vireo<A, B, C>(a: A, b: B, fn: (A, B) -> C) -> C { | |
fn(a, b) | |
} | |
func warbler<A, B>(fn1: (A, A) -> B, a: A) -> B { | |
fn1(a, a) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment