Functions

The following functions are available globally.

  • Undocumented

    Declaration

    Swift

    public func hListOf<A>(_ a: A) -> HList1<A>
  • Undocumented

    Declaration

    Swift

    public func hListOf<A, B>(_ a: A, _ b: B) -> HList2<A, B>
  • Undocumented

    Declaration

    Swift

    public func hListOf<A, B, C>(_ a: A, _ b: B, _ c: C) -> HList3<A, B, C>
  • Undocumented

    Declaration

    Swift

    public func hListOf<A, B, C, D>(_ a: A, _ b: B, _ c: C, _ d: D) -> HList4<A, B, C, D>
  • Undocumented

    Declaration

    Swift

    public func hListOf<A, B, C, D, E>(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E) -> HList5<A, B, C, D, E>
  • Undocumented

    Declaration

    Swift

    public func hListOf<A, B, C, D, E, F>(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E, _ f: F) -> HList6<A, B, C, D, E, F>
  • Undocumented

    Declaration

    Swift

    public func hListOf<A, B, C, D, E, F, G>(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E, _ f: F, _ g: G) -> HList7<A, B, C, D, E, F, G>
  • Undocumented

    Declaration

    Swift

    public func hListOf<A, B, C, D, E, F, G, H>(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E, _ f: F, _ g: G, _ h: H) -> HList8<A, B, C, D, E, F, G, H>
  • Undocumented

    Declaration

    Swift

    public func hListOf<A, B, C, D, E, F, G, H, I>(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E, _ f: F, _ g: G, _ h: H, _ i: I) -> HList9<A, B, C, D, E, F, G, H, I>
  • Undocumented

    Declaration

    Swift

    public func hListOf<A, B, C, D, E, F, G, H, I, J>(_ a: A, _ b: B, _ c: C, _ d: D, _ e: E, _ f: F, _ g: G, _ h: H, _ i: I, _ j: J) -> HList10<A, B, C, D, E, F, G, H, I, J>
  • Negates a boolean value.

    Declaration

    Swift

    public func not(_ a: Bool) -> Bool
  • Conjunction of two boolean values.

    Returns true if both inputs are true, or false otherwise.

    Declaration

    Swift

    public func and(_ a: Bool, _ b: Bool) -> Bool
  • Disjunction of two boolean values.

    Returns false if both inputs are false, or true otherwise.

    Declaration

    Swift

    public func or(_ a: Bool, _ b: Bool) -> Bool
  • Exclusive or of two boolean values.

    Returns true if both inputs have different truth value, or false if they are equal.

    Declaration

    Swift

    public func xor(_ a: Bool, _ b: Bool) -> Bool
  • Given a 0-ary function, provides a 0-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement(_ ff : @escaping () -> Bool) -> () -> Bool
  • Given a 1-ary function, provides a 1-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A>(_ ff : @escaping (A) -> Bool) -> (A) -> Bool
  • Given a 2-ary function, provides a 2-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A, B>(_ ff : @escaping (A, B) -> Bool) -> (A, B) -> Bool
  • Given a 3-ary function, provides a 3-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A, B, C>(_ ff : @escaping (A, B, C) -> Bool) -> (A, B, C) -> Bool
  • Given a 4-ary function, provides a 4-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A, B, C, D>(_ ff : @escaping (A, B, C, D) -> Bool) -> (A, B, C, D) -> Bool
  • Given a 5-ary function, provides a 5-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A, B, C, D, E>(_ ff : @escaping (A, B, C, D, E) -> Bool) -> (A, B, C, D, E) -> Bool
  • Given a 6-ary function, provides a 6-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A, B, C, D, E, F>(_ ff : @escaping (A, B, C, D, E, F) -> Bool) -> (A, B, C, D, E, F) -> Bool
  • Given a 7-ary function, provides a 7-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A, B, C, D, E, F, G>(_ ff : @escaping (A, B, C, D, E, F, G) -> Bool) -> (A, B, C, D, E, F, G) -> Bool
  • Given a 8-ary function, provides a 8-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A, B, C, D, E, F, G, H>(_ ff : @escaping (A, B, C, D, E, F, G, H) -> Bool) -> (A, B, C, D, E, F, G, H) -> Bool
  • Given a 9-ary function, provides a 9-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A, B, C, D, E, F, G, H, I>(_ ff : @escaping (A, B, C, D, E, F, G, H, I) -> Bool) -> (A, B, C, D, E, F, G, H, I) -> Bool
  • Given a 10-ary function, provides a 10-ary function that returns the complement boolean value.

    Declaration

    Swift

    public func complement<A, B, C, D, E, F, G, H, I, J>(_ ff : @escaping (A, B, C, D, E, F, G, H, I, J) -> Bool) -> (A, B, C, D, E, F, G, H, I, J) -> Bool
  • Curries a 2-ary function.

    Declaration

    Swift

    public func curry<A, B, C>(_ fun : @escaping (A, B) -> C) -> (A) -> (B) -> C
  • Uncurries a 2-ary function.

    Declaration

    Swift

    public func uncurry<A, B, C>(_ fun : @escaping (A) -> (B) -> C) -> (A, B) -> C
  • Curries a 3-ary function.

    Declaration

    Swift

    public func curry<A, B, C, D>(_ fun : @escaping (A, B, C) -> D) -> (A) -> (B) -> (C) -> D
  • Uncurries a 3-ary function.

    Declaration

    Swift

    public func uncurry<A, B, C, D>(_ fun : @escaping (A) -> (B) -> (C) -> D) -> (A, B, C) -> D
  • Curries a 4-ary function.

    Declaration

    Swift

    public func curry<A, B, C, D, E>(_ fun : @escaping (A, B, C, D) -> E) -> (A) -> (B) -> (C) -> (D) -> E
  • Uncurries a 4-ary function.

    Declaration

    Swift

    public func uncurry<A, B, C, D, E>(_ fun : @escaping (A) -> (B) -> (C) -> (D) -> E) -> (A, B, C, D) -> E
  • Curries a 5-ary function.

    Declaration

    Swift

    public func curry<A, B, C, D, E, F>(_ fun : @escaping (A, B, C, D, E) -> F) -> (A) -> (B) -> (C) -> (D) -> (E) -> F
  • Uncurries a 5-ary function.

    Declaration

    Swift

    public func uncurry<A, B, C, D, E, F>(_ fun : @escaping (A) -> (B) -> (C) -> (D) -> (E) -> F) -> (A, B, C, D, E) -> F
  • Curries a 6-ary function.

    Declaration

    Swift

    public func curry<A, B, C, D, E, F, G>(_ fun : @escaping (A, B, C, D, E, F) -> G) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> G
  • Uncurries a 6-ary function.

    Declaration

    Swift

    public func uncurry<A, B, C, D, E, F, G>(_ fun : @escaping (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> G) -> (A, B, C, D, E, F) -> G
  • Curries a 7-ary function.

    Declaration

    Swift

    public func curry<A, B, C, D, E, F, G, H>(_ fun : @escaping (A, B, C, D, E, F, G) -> H) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> H
  • Uncurries a 7-ary function.

    Declaration

    Swift

    public func uncurry<A, B, C, D, E, F, G, H>(_ fun : @escaping (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> H) -> (A, B, C, D, E, F, G) -> H
  • Memoizes a 1-ary function.

    Memoization is a useful technique to cache already computed values, specially in functions with a high computational cost. It requires the input parameter to the function to be Hashable in order to be able to save the computed result. This function returns a memoized function that behaves the same as the original one. Given an input, first invokation of the memoized function will compute the result and store it. Subsequent invokations with the same input will not be computed; the stored result will be returned instead.

    Declaration

    Swift

    public func memoize<A, B>(_ f : @escaping (A) -> B) -> (A) -> B where A : Hashable

    Parameters

    f

    Function to be memoized. This function must be pure and deterministic in order to have consistent results.

  • Memoizes a recursive 1-ary function.

    In order to memoize a recursive function, the recursive step must be memoized as well. In order to do so, callers of this function must pass a function that will receive the memoized function and the current input, and use both to provide the output. Input parameters must conform to Hashable. As an example, consider this implementation of a memoized factorial:

    let memoizedFactorial: (Int) -> Int = memoize { factorial, x in
       x == 0 ? 1 : x * factorial(x - 1)
    }
    

    Declaration

    Swift

    public func memoize<A, B>(_ f : @escaping ((A) -> B, A) -> B) -> (A) -> B where A : Hashable
  • Applies an argument to a 1-ary function.

    Declaration

    Swift

    public func |> <A, B>(a: A, fun: (A) -> B) -> B
  • Applies the first argument to a 2-ary function, returning a 1-ary function with the rest of the arguments of the original function.

    Declaration

    Swift

    public func |><A, B, C>(_ a : A, _ fun : @escaping (A, B) -> C) -> (B) -> C
  • Applies the first argument to a 3-ary function, returning a 2-ary function with the rest of the arguments of the original function.

    Declaration

    Swift

    public func |><A, B, C, D>(_ a : A, _ fun : @escaping (A, B, C) -> D) -> (B, C) -> D
  • Applies the first argument to a 4-ary function, returning a 3-ary function with the rest of the arguments of the original function.

    Declaration

    Swift

    public func |><A, B, C, D, E>(_ a : A, _ fun : @escaping (A, B, C, D) -> E) -> (B, C, D) -> E
  • Applies the first argument to a 5-ary function, returning a 4-ary function with the rest of the arguments of the original function.

    Declaration

    Swift

    public func |><A, B, C, D, E, F>(_ a : A, _ fun : @escaping (A, B, C, D, E) -> F) -> (B, C, D, E) -> F
  • Applies the first argument to a 6-ary function, returning a 5-ary function with the rest of the arguments of the original function.

    Declaration

    Swift

    public func |><A, B, C, D, E, F, G>(_ a : A, _ fun : @escaping (A, B, C, D, E, F) -> G) -> (B, C, D, E, F) -> G
  • Applies the first argument to a 7-ary function, returning a 6-ary function with the rest of the arguments of the original function.

    Declaration

    Swift

    public func |><A, B, C, D, E, F, G, H>(_ a : A, _ fun : @escaping (A, B, C, D, E, F, G) -> H) -> (B, C, D, E, F, G) -> H
  • Applies the first argument to a 8-ary function, returning a 7-ary function with the rest of the arguments of the original function.

    Declaration

    Swift

    public func |><A, B, C, D, E, F, G, H, I>(_ a : A, _ fun : @escaping (A, B, C, D, E, F, G, H) -> I) -> (B, C, D, E, F, G, H) -> I
  • Identity function. Returns the input without changing it.

    Declaration

    Swift

    public func id<A>(_ a: A) -> A
  • Given an input, provides a 0-ary function that always returns such value.

    Declaration

    Swift

    public func constant<A>(_ a: A) -> () -> A
  • Given an input, provides a 1-ary function that always returns such value.

    Declaration

    Swift

    public func constant<A, B>(_ a: A) -> (B) -> A
  • Given an input, provides a 2-ary function that always returns such value.

    Declaration

    Swift

    public func constant<A, B, C>(_ a: A) -> (B, C) -> A
  • Given an input, provides a 3-ary function that always returns such value.

    Declaration

    Swift

    public func constant<A, B, C, D>(_ a: A) -> (B, C, D) -> A
  • Given an input, provides a 4-ary function that always returns such value.

    Declaration

    Swift

    public func constant<A, B, C, D, E>(_ a: A) -> (B, C, D, E) -> A
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func compose<A, B>(_ g : @escaping (A) -> B, _ f : @escaping () -> A) -> () -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func compose<A, B>(_ g : @escaping (A) throws -> B, _ f : @escaping () -> A) -> () throws -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func compose<A, B>(_ g : @escaping (A) -> B, _ f : @escaping () throws -> A) -> () throws -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func compose<A, B>(_ g : @escaping (A) throws -> B, _ f : @escaping () throws -> A) -> () throws -> B
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func compose<A, B, C>(_ g : @escaping (B) -> C, _ f : @escaping (A) -> B) -> (A) -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func compose<A, B, C>(_ g : @escaping (B) throws -> C, _ f : @escaping (A) -> B) -> (A) throws -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func compose<A, B, C>(_ g : @escaping (B) -> C, _ f : @escaping (A) throws -> B) -> (A) throws -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func compose<A, B, C>(_ g : @escaping (B) throws -> C, _ f : @escaping (A) throws -> B) -> (A) throws -> C
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func andThen<A, B>(_ f : @escaping () -> A, _ g : @escaping (A) -> B) -> () -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func andThen<A, B>(_ f : @escaping () throws -> A, _ g : @escaping (A) -> B) -> () throws -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func andThen<A, B>(_ f : @escaping () -> A, _ g : @escaping (A) throws -> B) -> () throws -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func andThen<A, B>(_ f : @escaping () throws -> A, _ g : @escaping (A) throws -> B) -> () throws -> B
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func andThen<A, B, C>(_ f : @escaping (A) -> B, _ g : @escaping (B) -> C) -> (A) -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func andThen<A, B, C>(_ f : @escaping (A) throws -> B, _ g : @escaping (B) -> C) -> (A) throws -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func andThen<A, B, C>(_ f : @escaping (A) -> B, _ g : @escaping (B) throws -> C) -> (A) throws -> C
  • Undocumented

    Declaration

    Swift

    public func andThen<A, B, C>(_ f : @escaping (A) throws -> B, _ g : @escaping (B) throws -> C) -> (A) throws -> C
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func >>><A, B>(_ f : @escaping () -> A, _ g : @escaping (A) -> B) -> () -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func >>><A, B>(_ f : @escaping () throws -> A, _ g : @escaping (A) -> B) -> () throws -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func >>><A, B>(_ f : @escaping () -> A, _ g : @escaping (A) throws -> B) -> () throws -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func >>><A, B>(_ f : @escaping () throws -> A, _ g : @escaping (A) throws -> B) -> () throws -> B
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func >>><A, B, C>(_ f : @escaping (A) -> B, _ g : @escaping (B) -> C) -> (A) -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func >>><A, B, C>(_ f : @escaping (A) throws -> B, _ g : @escaping (B) -> C) -> (A) throws -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func >>><A, B, C>(_ f : @escaping (A) -> B, _ g : @escaping (B) throws -> C) -> (A) throws -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func >>><A, B, C>(_ f : @escaping (A) throws -> B, _ g : @escaping (B) throws -> C) -> (A) throws -> C
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func <<<<A, B>(_ g : @escaping (A) -> B, _ f : @escaping () -> A) -> () -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func <<<<A, B>(_ g : @escaping (A) throws -> B, _ f : @escaping () -> A) -> () throws -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func <<<<A, B>(_ g : @escaping (A) -> B, _ f : @escaping () throws -> A) -> () throws -> B
  • Composes a 0-ary function with a 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func <<<<A, B>(_ g : @escaping (A) throws -> B, _ f : @escaping () throws -> A) -> () throws -> B
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func <<<<A, B, C>(_ g : @escaping (B) -> C, _ f : @escaping (A) -> B) -> (A) -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func <<<<A, B, C>(_ g : @escaping (B) throws -> C, _ f : @escaping (A) -> B) -> (A) throws -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func <<<<A, B, C>(_ g : @escaping (B) -> C, _ f : @escaping (A) throws -> B) -> (A) throws -> C
  • Composes a 1-ary function with another 1-ary function.

    Returns a function that is the result of applying g to the output of f.

    Declaration

    Swift

    public func <<<<A, B, C>(_ g : @escaping (B) throws -> C, _ f : @escaping (A) throws -> B) -> (A) throws -> C
  • Given a 2-ary function, returns a 2-ary function where the argument list is reversed.

    Declaration

    Swift

    public func reverse<P1, P2, R>(_ f : @escaping (P1, P2) -> R) -> (P2, P1) -> R
  • Given a 3-ary function, returns a 3-ary function where the argument list is reversed.

    Declaration

    Swift

    public func reverse<P1, P2, P3, R>(_ f : @escaping (P1, P2, P3) -> R) -> (P3, P2, P1) -> R
  • Given a 4-ary function, returns a 4-ary function where the argument list is reversed.

    Declaration

    Swift

    public func reverse<P1, P2, P3, P4, R>(_ f : @escaping (P1, P2, P3, P4) -> R) -> (P4, P3, P2, P1) -> R
  • Given a 5-ary function, returns a 5-ary function where the argument list is reversed.

    Declaration

    Swift

    public func reverse<P1, P2, P3, P4, P5, R>(_ f : @escaping (P1, P2, P3, P4, P5) -> R) -> (P5, P4, P3, P2, P1) -> R
  • Given a 6-ary function, returns a 6-ary function where the argument list is reversed.

    Declaration

    Swift

    public func reverse<P1, P2, P3, P4, P5, P6, R>(_ f : @escaping (P1, P2, P3, P4, P5, P6) -> R) -> (P6, P5, P4, P3, P2, P1) -> R
  • Given a 7-ary function, returns a 7-ary function where the argument list is reversed.

    Declaration

    Swift

    public func reverse<P1, P2, P3, P4, P5, P6, P7, R>(_ f : @escaping (P1, P2, P3, P4, P5, P6, P7) -> R) -> (P7, P6, P5, P4, P3, P2, P1) -> R
  • Given a 8-ary function, returns a 8-ary function where the argument list is reversed.

    Declaration

    Swift

    public func reverse<P1, P2, P3, P4, P5, P6, P7, P8, R>(_ f : @escaping (P1, P2, P3, P4, P5, P6, P7, P8) -> R) -> (P8, P7, P6, P5, P4, P3, P2, P1) -> R
  • Given a 9-ary function, returns a 9-ary function where the argument list is reversed.

    Declaration

    Swift

    public func reverse<P1, P2, P3, P4, P5, P6, P7, P8, P9, R>(_ f : @escaping (P1, P2, P3, P4, P5, P6, P7, P8, P9) -> R) -> (P9, P8, P7, P6, P5, P4, P3, P2, P1) -> R
  • Given a 10-ary function, returns a 10-ary function where the argument list is reversed.

    Declaration

    Swift

    public func reverse<P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, R>(_ f : @escaping (P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) -> R) -> (P10, P9, P8, P7, P6, P5, P4, P3, P2, P1) -> R