mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-05 10:45:45 +00:00
34 lines
573 B
Swift
34 lines
573 B
Swift
//
|
|
// FunctionComposition.swift
|
|
// SiteGenerator
|
|
//
|
|
// Created by Sami Samhuri on 2019-11-18.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
infix operator |> :AdditionPrecedence
|
|
|
|
// MARK: Synchronous
|
|
|
|
public func |> <A, B, C> (
|
|
f: @escaping (A) -> B,
|
|
g: @escaping (B) -> C
|
|
) -> (A) -> C {
|
|
return { a in
|
|
let b = f(a)
|
|
let c = g(b)
|
|
return c
|
|
}
|
|
}
|
|
|
|
public func |> <A, B, C> (
|
|
f: @escaping (A) throws -> B,
|
|
g: @escaping (B) throws -> C
|
|
) -> (A) throws -> C {
|
|
return { a in
|
|
let b = try f(a)
|
|
let c = try g(b)
|
|
return c
|
|
}
|
|
}
|