Files

54 lines
1.0 KiB
Swift

//
// Operations.swift
// Jura
//
// Created by Jura on 8/14/19.
// Copyright © 2019 Jura. All rights reserved.
//
import Foundation
precedencegroup MonadicPrecedence {
associativity: left
higherThan: BitwiseShiftPrecedence
}
infix operator >>- : MonadicPrecedence
@inline(__always)
@discardableResult
public func >>-<T, U>(a: T?, f: (T) throws -> U?) rethrows -> U? {
switch a {
case .some(let x):
return try f(x)
case .none:
return nil
}
}
// MARK: <<< / >>>
precedencegroup FunctionApplicationPrecedenceLeft {
lowerThan: AssignmentPrecedence
associativity: left
}
infix operator >>> : FunctionApplicationPrecedenceLeft
@inline(__always)
public func >>><T, U>(x: T, f: (T) throws -> U) rethrows -> U {
return try f(x)
}
precedencegroup FunctionApplicationPrecedenceRight {
lowerThan: AssignmentPrecedence
associativity: right
}
infix operator <<< : FunctionApplicationPrecedenceRight
@inline(__always)
public func <<<<T, U>(f: (T) throws -> U, x: T) rethrows -> U {
return try f(x)
}