Functions
The following functions are available globally.
-
Return the result of evaluating a function
fwith argument(s)a.Declaration
Swift
public func pipe<A, B>(_ a: A, _ f: (A) -> B) -> BParameters
aValue to be passed to
f.fFunction to evaluate.
Return Value
f(a)
-
Infix
See morepipeoperator.Declaration
Swift
public func |><A, B>(a: A, f: (A) -> B) -> BParameters
aValue to be passed to
f.fFunction to evaluate.
Return Value
f(a)
-
Returns a new function which returns the result of evaluating a function
gwith 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) -> CParameters
fFirst function to be called.
gSecond function to be called.
Return Value
A function which returns the result of calling
gwith the output of callingfwith the function’s input:g(f($0)). -
Infix
See morecomposeoperator.Declaration
Swift
public func >>><A, B, C>(_ f: @escaping (A) -> B, _ g: @escaping (B) -> C) -> (A) -> CParameters
fFirst function to be called.
gSecond function to be called.
Return Value
A function which returns the result of calling
gwith the output of callingfwith the function’s input:g(f($0)). -
A function which returns its argument.
Declaration
Swift
public func identity<A>(_ a: A) -> AParameters
avalue to return.
Return Value
a. -
A function which ignores its argument.
Declaration
Swift
public func ignore<A>(_: A) -> VoidParameters
avalue 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) -> CParameters
ffunction 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) -> DParameters
ffunction 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) -> EParameters
ffunction 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) -> BParameters
ffunction 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) -> CParameters
ffunction 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) -> DParameters
ffunction 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) -> EParameters
ffunction 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) -> CParameters
fa 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) -> DParameters
fa 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) -> EParameters
fa 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) -> CParameters
fa 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) -> DParameters
fa 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) -> EParameters
fa function.
Return Value
a function which accepts curried arguments in the reverse order.
-
Infix version of
See morefcomposed withbind. Returns a function that maps a value through bothfandg.Declaration
Return Value
the result of
giffandgare 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
ffunction 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) -> AParameters
ffunction to evaluate.
Return Value
a function which maps a value to itself, passig it to
ffirst. -
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 -> AParameters
ffunction to evaluate.
Return Value
a function which maps a value to itself, passig it to
ffirst. -
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
ffunction 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
nilwas returned, converting an optional to a two-way track.Declaration
Parameters
ffunction to evaluate.
Return Value
a function mapping a value to a
Result.
View on GitHub
Install in Dash
Functions Reference