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 is right (e.g when you have Either<Error, T>):

    task.responseApi(UIImage.Type) { image in
        output.avatarWasLoaded <^> image
    }
    
    See more

    Declaration

    Swift

    public func <^><T, L, U>(_ transform: (T) -> U, _ arg: Either<L, T>) -> Either<L, 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) -> Either<V, T> -> Either<V, U>
    (<^>)   : (T -> U) -> Either<V, T> -> Either<V, U>
    

    Usually this operator is used for debugging.

    See also

    <^> operator.
    See more

    Declaration

    Swift

    public func <^<T, U, V>(_ transform: T, _ arg: Either<U, V>) -> Either<U, T>
  • Is flipped version of <^

    See also

    <^>, <^ operators.
    See more

    Declaration

    Swift

    public func ^><T, U, V>(_ arg: Either<T, U>, _ transform: V) -> Either<T, V>
  • 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)
    }
    
    See more

    Declaration

    Swift

    public func >>-<T, U, V>(_ arg: Either<T, U>, _ transform: (U) -> Either<T, V>) -> Either<T, V>
  • Same as >>-, but with the arguments interchanged.

    See also

    >>- operator.
    See more

    Declaration

    Swift

    public func -<<<T, U, V>(_ transform: (T) -> Either<U, V>, _ arg: Either<U, T>) -> Either<U, V>
  • Sequential application.

    Apply the unwrapped function to the unwrapped argument.

    See more

    Declaration

    Swift

    public func <*><T, U, V>(_ transform: Either<T, (U) -> V>, arg: Either<T, U>) -> Either<T, V>

    Parameters

    transform

    Wrapped function.

    arg

    Wrapped argument.

    Return Value

    rigth if the function and the argument is right, otherwise left.

  • Lift a binary function to actions.

    The function apply function to the unwrapped arguments if both Either is right.

    Declaration

    Swift

    public func liftA2<T, U, V, W>(_ transform: (T, U) -> V,
                                   _ arg1: Either<W, T>,
                                   _ arg2: Either<W, U>) -> Either<W, V>

    Parameters

    transform

    The function to be applied to the arguments.

    arg1

    The first argument.

    arg2

    The second argument.

    Return Value

    right when both arguments are right, otherwise left.

  • Lift a ternary function to actions.

    The function apply function to the unwrapped arguments if all Either is right.

    Declaration

    Swift

    public func liftA3<T, U, V, W, X>(_ transform: (T, U, V) -> W,
                                      _ arg1: Either<X, T>,
                                      _ arg2: Either<X, U>,
                                      _ arg3: Either<X, V>) -> Either<X, 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

    right when all arguments are right, otherwise left.

  • 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 is some:

    let data = ... // Give data
    let image = UIImage.init <^> data
    
    See more

    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.
    See more

    Declaration

    Swift

    public func <^<T, U>(_ transform: T, _ arg: U?) -> T?
  • Is flipped version of <^

    See also

    <^>, <^ operators.
    See more

    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
    }
    
    See more

    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.
    See more

    Declaration

    Swift

    public func -<<<T, U>(_ transform: (T) -> U?, _ arg: T?) -> U?
  • Sequential application.

    Apply the unwrapped function to the unwrapped argument.

    See more

    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 is some, otherwise none.

  • 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 are some, otherwise none.

  • Lift a ternary function to actions.

    The function apply function to the unwrapped arguments if all Optional is some.

    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 are some, otherwise none.

  • 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]
    
    See more

    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.
    See more

    Declaration

    Swift

    public func <^<T, U>(_ transform: T, _ arg: [U]) -> [T]
  • Is flipped version of <^

    See also

    <^>, <^ operators.
    See more

    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
    
    See more

    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.
    See more

    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 }
    
    See more

    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
    
    See more

    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.
    See more

    Declaration

    Swift

    public func <^<T, U: Hashable, V>(_ transform: T, _ arg: [U: V]) -> [U: T]
  • Is flipped version of <^

    See also

    <^>, <^ operators.
    See more

    Declaration

    Swift

    public func ^><T: Hashable, U, V>(_ arg: [T: U], _ transform: V) -> [T: V]
  • Identity function.

    Declaration

    Swift

    public func id<T>(_ identity: T) -> T
  • const(x) is a unary function which evaluates to x for all inputs.

    Declaration

    Swift

    public func const<T, V>( _ const: T) -> (V) -> T
  • Function composition.

    See more

    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 as f <| 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 more

    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 as x |> 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 more

    Declaration

    Swift

    public func |> <A, B>(lhs: A, rhs: (A) -> B) -> B