1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Prism conjunction.

This commit is contained in:
Rob Rix 2015-09-21 17:23:29 -04:00
parent 1d0a54d62a
commit 1e9be8b9b0
2 changed files with 18 additions and 0 deletions

View File

@ -28,6 +28,11 @@ infix operator >>- {
precedence 100
}
infix operator &&& {
associativity left
precedence 120
}
prefix operator ^ {}
postfix operator * {}

View File

@ -39,3 +39,16 @@ extension Prism where To : ArrayConvertible {
return map(transform(Prism<To.Element, To.Element>(forward: { $0 }, backward: { $0 })))
}
}
public func &&& <From, A, B> (left: Prism<From, A>, right: Prism<From, B>) -> Prism<From, (A, B)> {
return Prism(
forward: {
if let a = left.forward($0), b = right.forward($0) {
return (a, b)
}
return nil
},
backward: {
(left.backward($0), right.backward($1)).1
})
}