Functions
The following functions are available globally.
-
Undocumented
Declaration
Swift
public func curry<A, B>(_ function: @escaping (A) -> B) -> (A) -> B
-
Undocumented
Declaration
Swift
public func curry<A, B, C>(_ function: @escaping ((A, B)) -> C) -> (A) -> (B) -> C
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D>(_ function: @escaping ((A, B, C)) -> D) -> (A) -> (B) -> (C) -> D
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E>(_ function: @escaping ((A, B, C, D)) -> E) -> (A) -> (B) -> (C) -> (D) -> E
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F>(_ function: @escaping ((A, B, C, D, E)) -> F) -> (A) -> (B) -> (C) -> (D) -> (E) -> F
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G>(_ function: @escaping ((A, B, C, D, E, F)) -> G) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> G
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H>(_ function: @escaping ((A, B, C, D, E, F, G)) -> H) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> H
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I>(_ function: @escaping ((A, B, C, D, E, F, G, H)) -> I) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> I
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J>(_ function: @escaping ((A, B, C, D, E, F, G, H, I)) -> J) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> J
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J)) -> K) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> K
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K)) -> L) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> L
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L, M>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K, L)) -> M) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> (L) -> M
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K, L, M)) -> N) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> (L) -> (M) -> N
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K, L, M, N)) -> O) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> (L) -> (M) -> (N) -> O
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K, L, M, N, O)) -> P) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> (L) -> (M) -> (N) -> (O) -> P
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P)) -> Q) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> (L) -> (M) -> (N) -> (O) -> (P) -> Q
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q)) -> R) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> (L) -> (M) -> (N) -> (O) -> (P) -> (Q) -> R
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R)) -> S) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> (L) -> (M) -> (N) -> (O) -> (P) -> (Q) -> (R) -> S
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S)) -> T) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> (L) -> (M) -> (N) -> (O) -> (P) -> (Q) -> (R) -> (S) -> T
-
Undocumented
Declaration
Swift
public func curry<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U>(_ function: @escaping ((A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T)) -> U) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> (K) -> (L) -> (M) -> (N) -> (O) -> (P) -> (Q) -> (R) -> (S) -> (T) -> U
-
An infix synonym for
map(_:)
.The name of this operation is allusion to
^
. Note the similarities between their types:(^) : (T -> U) T -> U (<^>) : (T -> U) -> [T] -> [U]
Examples:
If you need transform all elements of array:
let json: [JSON] = ... let bankCards = BankCard.create <^> json // bankCards is [BankCard]
Declaration
Swift
@discardableResult public func <^> <T, U>(transform: (T) -> U, arg: [T]) -> [U]
-
Replace all locations in the input with the same value. The default definition is
map { _ in transform }
, but this may be overridden with a more efficient version.The name of this operation is allusion in
<^>
. Note the similarities between their types:(<^ ) : ( U) -> [T] -> [U] (<^>) : (T -> U) -> [T] -> [U]
Usually this operator is used for debugging.
See also
<^>
operator.Declaration
Swift
public func <^ <T, U>(transform: T, arg: [U]) -> [T]
-
Is flipped version of
<^
See also
<^>
,<^
operators.Declaration
Swift
public func ^> <T, U>(arg: [T], transform: U) -> [U]
-
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
Example:
let packageToOperation: (Package) -> [Operation] let packages: [Package] = ... // operations is [Operation] let operations = packages >>- packageToOperation
Declaration
Swift
public func >>- <T, U>(arg: [T], transform: (T) -> [U]) -> [U]
-
Same as
>>-
, but with the arguments interchanged.Example:
let packageToOperation: (Package) -> [Operation] let packages: [Package] = ... // operations is [Operation] let operations = packageToOperation -<< packages
See also
>>-
operator.Declaration
Swift
public func -<< <T, U>(transform: (T) -> [U], arg: [T]) -> [U]
-
Sequential application.
Apply all functions to the all values.
Example:
let parsers: [(JSON) -> Operation?] = ... let data: [JSON] = ... // operations is [Operation?] let opetations = parsers <*> json // cleanOperations is [Operation] let cleanOperations = operations.flatMap { $0 }
Declaration
Swift
public func <*> <T, U>(transform: [(T) -> U], arg: [T]) -> [U]
Parameters
transform
Array of functions.
arg
Array of arguments.
Return Value
array of applying all functions to all argumaents.
-
Lift a binary function to actions.
The function apply function to all arguments.
Declaration
Swift
public func liftA2<T, U, V>(_ transform: (T, U) -> V, _ arg1: [T], _ arg2: [U]) -> [V]
Parameters
transform
The function to be applied to the arguments.
arg1
The first argument.
arg2
The second argument.
Return Value
Array of applying function to arguments.
-
Lift a ternary function to actions.
The function apply function to all arguments.
Declaration
Swift
public func liftA3<T, U, V, W>(_ transform: (T, U, V) -> W, _ arg1: [T], _ arg2: [U], _ arg3: [V]) -> [W]
Parameters
transform
The function to be applied to the arguments.
arg1
The first argument.
arg2
The second argument.
arg3
The third argument.
Return Value
Array of applying function to arguments.
-
An infix synonym for
map(_:)
.The name of this operation is allusion to
^
. Note the similarities between their types:(^) : (T -> U) T -> U (<^>) : (T -> U) -> [V: T] -> [V: U]
Examples:
If you need transform all values of
Dictionary
:let jsonToPrice: (JSON) -> Price = ... let data: [Currency: JSON] = ... // paymentMethods is [Currency: Price] let paymentMethods = jsonToPrice <^> data
Declaration
Swift
public func <^><T, U, Key>(_ transform: (T) -> U, _ arg: [Key: T]) -> [Key: U]
-
Replace all locations in the input with the same value. The default definition is
map { _ in transform }
, but this may be overridden with a more efficient version.The name of this operation is allusion in
<^>
. Note the similarities between their types:(<^ ) : ( U) -> [V: T] -> [V: U] (<^>) : (T -> U) -> [V: T] -> [V: U]
Usually this operator is used for debugging.
See also
<^>
operator.Declaration
Swift
public func <^ <T, U, V>(transform: T, arg: [U : V]) -> [U : T] where U : Hashable
-
Is flipped version of
<^
See also
<^>
,<^
operators.Declaration
Swift
public func ^> <T, U, V>(arg: [T : U], transform: V) -> [T : V] where T : Hashable
-
An infix synonym for
map(_:)
.The name of this operation is allusion to
^
. Note the similarities between their types:(^) : (T -> U) T -> U (<^>) : (T -> U) -> Either<V, T> -> Either<V, U>
Examples:
If you need call function when
Either
isright
(e.g when you haveEither<Error, T>
):task.responseApi(UIImage.Type) { image in output.avatarWasLoaded <^> image }
-
Replace all locations in the input with the same value. The default definition is
map { _ in transform }
, but this may be overridden with a more efficient version.The name of this operation is allusion in
<^>
. Note the similarities between their types:(<^ ) : ( U) -> Either<V, T> -> Either<V, U> (<^>) : (T -> U) -> Either<V, T> -> Either<V, U>
Usually this operator is used for debugging.
See also
<^>
operator.
-
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
Example:
func imageFromPng(_ data: Data) -> Result<UIImage> { ... } task.responseApi { (data: Result<Data>) in let image = data >>- imageFromPng image.first(output.didLoadImage) .second(output.didFailLoadImage) }
-
Sequential application.
Apply the unwrapped function to the unwrapped argument.
Declaration
Parameters
transform
Wrapped function.
arg
Wrapped argument.
Return Value
rigth
if the function and the argument is right, otherwiseleft
. -
Lift a binary function to actions.
The function apply function to the unwrapped arguments if both Either is right.
Declaration
Parameters
transform
The function to be applied to the arguments.
arg1
The first argument.
arg2
The second argument.
Return Value
right
when both arguments areright
, otherwise left. -
Lift a ternary function to actions.
The function apply function to the unwrapped arguments if all
Either
isright
.Declaration
Parameters
transform
The function to be applied to the arguments.
arg1
The first argument.
arg2
The second argument.
arg3
The third argument.
Return Value
right
when all arguments areright
, otherwiseleft
.
-
An infix synonym for
map(_:)
.The name of this operation is allusion to
^
. Note the similarities between their types:(^) : (T -> U) T -> U (<^>) : (T -> U) -> T? -> U?
Examples:
If you need call function when
Optional
issome
:let data = ... // Give data let image = UIImage.init <^> data
Declaration
Swift
@discardableResult public func <^> <T, U>(transform: (T) -> U, arg: T?) -> U?
-
Replace all locations in the input with the same value.
The name of this operation is allusion in
<^>
. Note the similarities between their types:(<^>) : (T -> U) -> T? -> U? (<^) : ( U) -> T? -> U?
Usually this operator is used for debugging.
See also
<^>
operator.Declaration
Swift
public func <^ <T, U>(transform: T, arg: U?) -> T?
-
Is flipped version of
<^
See also
<^>
,<^
operators.Declaration
Swift
public func ^> <T, U>(arg: T?, transform: U) -> U?
-
Sequentially compose two actions, passing any value produced by the first as an argument to the second.
Example:
func imageFromPng(_ data: Data) -> UIImage? { ... } task.responseApi { (data: Data?) in let image = data >>- imageFromPng output.didLoadImage <^> image }
Declaration
Swift
public func >>- <T, U>(arg: T?, transform: (T) -> U?) -> U?
-
Same as
>>-
, but with the arguments interchanged.Example:
func imageFromPng(_ data: Data) -> UIImage? { ... } task.responseApi { (data: Data?) in let image = imageFromPng -<< data output.didLoadImage <^> image }
See also
>>-
operator.Declaration
Swift
public func -<< <T, U>(transform: (T) -> U?, arg: T?) -> U?
-
Sequential application.
Apply the unwrapped function to the unwrapped argument.
Declaration
Swift
public func <*><T, U>(_ transform: ((T) -> U)?, arg: T?) -> U?
Parameters
transform
Wrapped function.
arg
Wrapped argument.
Return Value
some
if the function and the argument issome
, otherwisenone
. -
Lift a binary function to actions.
The function apply function to the unwrapped arguments if both
Optional
is right.Example:
let value: NSNumber? = 0.58 let text = liftA2(NumberFormatter.localizedString, value, .percent) debugPrint(text) // prints Optional("58 %")
Declaration
Swift
public func liftA2<T, U, V>(_ transform: (T, U) -> V, _ arg1: T?, _ arg2: U?) -> V?
Parameters
transform
The function to be applied to the arguments.
arg1
The first argument.
arg2
The second argument.
Return Value
some
when both arguments aresome
, otherwisenone
. -
Lift a ternary function to actions.
The function apply function to the unwrapped arguments if all
Optional
issome
.Seealso
liftA2(_:_:_:)
Declaration
Swift
public func liftA3<T, U, V, W>(_ transform: (T, U, V) -> W, _ arg1: T?, _ arg2: U?, _ arg3: V?) -> W?
Parameters
transform
The function to be applied to the arguments.
arg1
The first argument.
arg2
The second argument.
arg3
The third argument.
Return Value
some
when all arguments aresome
, otherwisenone
. -
Identity function.
Seealso
Identity functionDeclaration
Swift
public func id<T>(_ identity: T) -> T
-
const(x)
is a unary function which evaluates tox
for all inputs.Declaration
Swift
public func const<T, V>(_ const: T) -> (V) -> T
-
Function composition.
Seealso
Function compositionDeclaration
Swift
public func • <A, B, C>(lhs: @escaping (B) -> C, rhs: @escaping (A) -> B) -> (A) -> C
-
Application operator. This operator is redundant, since ordinary application
f(x)
means the same asf <| x
. However,<|
has low, right-associative binding precedence, so it sometimes allows parentheses to be omitted; for example:f <| g <| h(x) = f(g(h(x)))
It is also useful in higher-order situations, such as zipWith(<|, fs, xs).
Declaration
Swift
public func <| <A, B>(lhs: (A) -> B, rhs: A) -> B
-
Application operator. This operator is redundant, since ordinary application
f(x)
means the same asx |> f
. However,|>
has low, left-associative binding precedence, so it sometimes allows parentheses to be omitted; for example:h(x) |> g |> f = f(g(h(x)))
It is also useful in higher-order situations, such as zipWith(|>, fs, xs).
Declaration
Swift
public func |> <A, B>(lhs: A, rhs: (A) -> B) -> B