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

Array functor

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

Array monad

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

Array applicative

  • 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.

Dictionary functor

  • 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

Either functor

  • 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
    }
    

    Declaration

    Swift

    @discardableResult
    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.

    Declaration

    Swift

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

    See also

    <^>, <^ operators.

    Declaration

    Swift

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

Either monad

  • 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)
    }
    

    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.

    Declaration

    Swift

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

Either applicative

  • Sequential application.

    Apply the unwrapped function to the unwrapped argument.

    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.

Optional functor

  • 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
    

    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?

Optional monad

  • 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?

Optional applicative

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

  • 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.

    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).

    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).

    Declaration

    Swift

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