Functions
The following functions are available globally.
-
Return the result of evaluating a function
f
with argument(s)a
.Declaration
Swift
public func pipe<A, B>(_ a: A, _ f: (A) -> B) -> B
Parameters
a
Value to be passed to
f
.f
Function to evaluate.
Return Value
f(a)
-
Infix
See morepipe
operator.Declaration
Swift
public func |><A, B>(a: A, f: (A) -> B) -> B
Parameters
a
Value to be passed to
f
.f
Function to evaluate.
Return Value
f(a)
-
Returns a new function which returns the result of evaluating a function
g
with the result of evaluating another functionf
.Declaration
Swift
public func compose<A, B, C>(_ f: @autoclosure @escaping () -> (A) -> B, _ g: @autoclosure @escaping () -> (B) -> C) -> (A) -> C
Parameters
f
First function to be called.
g
Second function to be called.
Return Value
A function which returns the result of calling
g
with the output of callingf
with the function’s input:g(f($0))
. -
Infix
See morecompose
operator.Declaration
Swift
public func >>><A, B, C>(_ f: @escaping (A) -> B, _ g: @escaping (B) -> C) -> (A) -> C
Parameters
f
First function to be called.
g
Second function to be called.
Return Value
A function which returns the result of calling
g
with the output of callingf
with the function’s input:g(f($0))
. -
A function which returns its argument.
Declaration
Swift
public func identity<A>(_ a: A) -> A
Parameters
a
value to return.
Return Value
a
. -
A function which ignores its argument.
Declaration
Swift
public func ignore<A>(_: A) -> Void
Parameters
a
value to ignore.
-
Create a curried version of a two-argument function.
Declaration
Swift
public func curry<A, B, C>(_ f: @autoclosure @escaping () -> (A, B) -> C) -> (A) -> (B) -> C
Parameters
f
function to curry.
Return Value
a chain of functions each taking a single argument.
-
Create a curried version of a three-argument function.
Declaration
Swift
public func curry<A, B, C, D>(_ f: @autoclosure @escaping () -> (A, B, C) -> D) -> (A) -> (B) -> (C) -> D
Parameters
f
function to curry.
Return Value
a chain of functions each taking a single argument.
-
Create a curried version of a four-argument function.
Declaration
Swift
public func curry<A, B, C, D, E>(_ f: @autoclosure @escaping () -> (A, B, C, D) -> E) -> (A) -> (B) -> (C) -> (D) -> E
Parameters
f
function to curry.
Return Value
a chain of functions each taking a single argument.
-
Create a function accepting an ignored argument.
Declaration
Swift
public func uncurry<A, B>(_ f: @autoclosure @escaping () -> () -> B) -> (A) -> B
Parameters
f
function to uncurry.
Return Value
A function which ignores its argument, returning f().
-
Convert a curried function into one that takes two arguments.
Declaration
Swift
public func uncurry<A, B, C>(_ f: @autoclosure @escaping () -> (A) -> (B) -> C) -> (A, B) -> C
Parameters
f
function to uncurry.
Return Value
A function taking two arguments.
-
Convert a curried function into one that takes three arguments.
Declaration
Swift
public func uncurry<A, B, C, D>(_ f: @autoclosure @escaping () -> (A) -> (B) -> (C) -> D) -> (A, B, C) -> D
Parameters
f
function to uncurry.
Return Value
A function taking three arguments.
-
Convert a curried function into one that takes four arguments.
Declaration
Swift
public func uncurry<A, B, C, D, E>(_ f: @autoclosure @escaping () -> (A) -> (B) -> (C) -> (D) -> E) -> (A, B, C, D) -> E
Parameters
f
function to uncurry.
Return Value
A function taking four arguments.
-
Reverse the order of a two-argument function’s arguments.
Declaration
Swift
public func reverse<A, B, C>(_ f: @autoclosure @escaping () -> (A, B) -> C) -> (B, A) -> C
Parameters
f
a function.
Return Value
a function which accepts arguments in the reverse order.
-
Reverse the order of a three-argument function’s arguments.
Declaration
Swift
public func reverse<A, B, C, D>(_ f: @autoclosure @escaping () -> (A, B, C) -> D) -> (C, B, A) -> D
Parameters
f
a function.
Return Value
a function which accepts arguments in the reverse order.
-
Reverse the order of a four-argument function’s arguments.
Declaration
Swift
public func reverse<A, B, C, D, E>(_ f: @autoclosure @escaping () -> (A, B, C, D) -> E) -> (D, C, B, A) -> E
Parameters
f
a function.
Return Value
a function which accepts arguments in the reverse order.
-
Reverse the order of a two-curry function.
Declaration
Swift
public func reverse<A, B, C>(_ f: @autoclosure @escaping () -> (A) -> (B) -> C) -> (B) -> (A) -> C
Parameters
f
a function.
Return Value
a function which accepts curried arguments in the reverse order.
-
Reverse the order of a three-curry function.
Declaration
Swift
public func reverse<A, B, C, D>(_ f: @autoclosure @escaping () -> (A) -> (B) -> (C) -> D) -> (C) -> (B) -> (A) -> D
Parameters
f
a function.
Return Value
a function which accepts curried arguments in the reverse order.
-
Reverse the order of a four-curry function.
Declaration
Swift
public func reverse<A, B, C, D, E>(_ f: @autoclosure @escaping () -> (A) -> (B) -> (C) -> (D) -> E) -> (D) -> (C) -> (B) -> (A) -> E
Parameters
f
a function.
Return Value
a function which accepts curried arguments in the reverse order.
-
Infix version of
See moref
composed withbind
. Returns a function that maps a value through bothf
andg
.Declaration
Return Value
the result of
g
iff
andg
are both successful, a failure otherwise. -
Creates a switched function that always returns success.
Declaration
Swift
public func turnout<A, B, C>(_ f: @autoclosure @escaping () -> (A) -> B) -> (A) -> Result<B, C>
Parameters
f
function being evaluated.
Return Value
a function mapping a value to a result via
f
. -
Pipes a value to another function, returning the original value instead.
Declaration
Swift
public func tee<A, B>(_ f: @autoclosure @escaping () -> (A) -> B) -> (A) -> A
Parameters
f
function to evaluate.
Return Value
a function which maps a value to itself, passig it to
f
first. -
Pipes a value to another function, returning the original value instead.
This version may throw.
Declaration
Swift
public func tee<A, B>(_ f: @autoclosure @escaping () -> (A) throws -> B) -> (A) throws -> A
Parameters
f
function to evaluate.
Return Value
a function which maps a value to itself, passig it to
f
first. -
Create a function that interprets a thrown error as a failed result.
Declaration
Swift
public func tryCatch<A, B>(_ f: @autoclosure @escaping () -> (A) throws -> B) -> (A) -> Result<B, Error>
Parameters
f
function evaluated with the passed-in value.
Return Value
a function mapping a value to a
Result
. -
Evaluate a function returning an optional value, returning a failure if
nil
was returned, converting an optional to a two-way track.Declaration
Parameters
f
function to evaluate.
Return Value
a function mapping a value to a
Result
.