Functions
The following functions are available globally.
-
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>
):
See moretask.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:
See morefunc imageFromPng(_ data: Data) -> Result<UIImage> { ... } task.responseApi { (data: Result<Data>) in let image = data >>- imageFromPng image.first(output.didLoadImage) .second(output.didFailLoadImage) }
-
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
:
See morelet data = ... // Give data let image = UIImage.init <^> data
Declaration
Swift
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?
-
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:
See morefunc 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?
-
Declaration
Swift
public func <*><T, U>(_ transform: Optional<(T) -> U>, arg: Optional<T>) -> Optional<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: Optional<T>, _ arg2: Optional<U>) -> Optional<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: Optional<T>, _ arg2: Optional<U>, _ arg3: Optional<V>) -> Optional<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
.
-
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:
See morelet json: [JSON] = ... let bankCards = BankCard.create <^> json // bankCards is [BankCard]
Declaration
Swift
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]
-
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:
See morelet 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:
See morelet 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
:
See morelet jsonToPrice: (JSON) -> Price = ... let data: [Currency: JSON] = ... // paymentMethods is [Currency: Price] let paymentMethods = jsonToPrice <^> data
Declaration
Swift
public func <^><T, U, Key: Hashable>(_ 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: Hashable, V>(_ transform: T, _ arg: [U: V]) -> [U: T]
-
Declaration
Swift
public func ^><T: Hashable, U, V>(_ arg: [T: U], _ transform: V) -> [T: V]
-
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
-
Declaration
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).
See moreDeclaration
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).
See moreDeclaration
Swift
public func |> <A, B>(lhs: A, rhs: (A) -> B) -> B