Created
April 14, 2017 13:57
-
-
Save andrevidela/45c734248a3cb0a0507123c89df08699 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/// Partially applies the right argument of a binary function | |
func partialRightApply<A, B, C>(_ f: @escaping (A, B) -> C, arg rhs: B) -> (A) -> C { | |
return {lhs in f(lhs, rhs)} | |
} | |
prefix operator > | |
prefix func > <T: Comparable>(rhs: T) -> (T) -> Bool { | |
return partialRightApply(>, arg: rhs) | |
} | |
prefix operator ?< | |
prefix func ?< <T: Comparable>(rhs: T) -> (T) -> Bool { | |
return partialRightApply(<, arg: rhs) | |
} | |
prefix operator ?> | |
prefix func ?> <T: Comparable>(rhs: T) -> (T) -> Bool { | |
return partialRightApply(>, arg: rhs) | |
} | |
/// Partially applies the left argument of a binary function | |
func partialLeftApply<A, B, C>(_ f: @escaping (A, B) -> C, arg lhs: A) -> (B) -> C { | |
return {rhs in f(lhs, rhs)} | |
} | |
postfix operator >? | |
postfix func >? <T: Comparable>(lhs: T) -> (T) -> Bool { | |
return partialLeftApply(>, arg: lhs) | |
} | |
postfix operator <? | |
postfix func <? <T: Comparable>(lhs: T) -> (T) -> Bool { | |
return partialLeftApply(<, arg: lhs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment