April 2017
Intermediate to advanced
316 pages
9h 33m
English
Let's define a new custom operator to use instead of our composed function:
precedencegroup AssociativityLeft { associativity: left } infix operator |> : AssociativityLeft func |> <T, V>(f: @escaping (T) -> V, g: @escaping (V) -> V ) -> (T) -> V { return { x in g(f(x)) } } let composedWithCustomOperator = extractElements |> formatWithCurrency composedWithCustomOperator("10,20,40,30,80,60") // The result will be: ["10$", "20$", "40$", "30$", "80$", "60$"]
In this example, we have defined a new operator, |>, that takes two generic functions and combines them, returning a function that has the first function's input as the parameter and the second function's return as the return type.
As this new ...
Read now
Unlock full access