Skip to content

Instantly share code, notes, and snippets.

@eMdOS
Created May 3, 2020 04:32
Show Gist options
  • Save eMdOS/d1114c69e02b64888cad5daee0fc92de to your computer and use it in GitHub Desktop.
Save eMdOS/d1114c69e02b64888cad5daee0fc92de to your computer and use it in GitHub Desktop.
func compose<A, B, C>(
f: @escaping (A) -> B, // f: A -> B
g: @escaping (B) -> C // g: B -> C
) -> (A) -> C { // h: A -> C = g • f
return { a in
g(f(a)) // g • f
}
}
// ... then
compose(f: Double.init(_:), g: String.init(_:))(1)
// which under the hood is the same that:
String(Double(Int(1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment