Skip to content

Commit 71c2c80

Browse files
author
Robert F. Dickerson
committed
Improve Pipes
1 parent f44a03f commit 71c2c80

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.swift-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0

Sources/Pipes.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@
1414
limitations under the License.
1515
*/
1616

17-
infix operator |> {associativity left precedence 100}
18-
public func |> <T,S>(lhs: T, rhs: (T)->S) -> S {
19-
return rhs(lhs)
20-
}
17+
precedencegroup LeftFunctionalApply {
18+
associativity: left
19+
higherThan: AssignmentPrecedence
20+
lowerThan: TernaryPrecedence
21+
}
22+
23+
// pipe val into monadic fn
24+
infix operator |> : LeftFunctionalApply
25+
26+
// pipe val into monadic fn
27+
@discardableResult
28+
public func |> <A, B> ( x: A, f: (A) throws -> B ) rethrows -> B {
29+
return try f(x)
30+
}

0 commit comments

Comments
 (0)