1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 21:52:59 +03:00
semantic/prototype/Doubt/Prelude.swift
2015-10-06 11:02:22 -04:00

32 lines
525 B
Swift

func fix<T, U>(f: (T -> U) -> T -> U) -> T -> U {
return { f(fix(f))($0) }
}
func id<A>(a: A) -> A {
return a
}
func const<A, B>(a: A)(_ b: B) -> A {
return a
}
func >>> <T, U, V> (f: T -> U, g: U -> V) -> T -> V {
return { g(f($0)) }
}
extension Optional {
static func equals(param: (Wrapped, Wrapped) -> Bool)(_ left: Wrapped?, _ right: Wrapped?) -> Bool {
switch (left, right) {
case let (.Some(a), .Some(b)):
return param(a, b)
case (.None, .None):
return true
default:
return false
}
}
}