Functions

The following functions are available globally.

  • Simple wrapper for dispatch_after that simplifies the most common use case (i.e., dispatch this block after X number of seconds).

    Declaration

    Swift

    public func after (seconds seconds:NSTimeInterval, onQueue queue:dispatch_queue_t, execute block:dispatch_block_t)
  • Randomly chooses a date in between startDate and endDate and returns it.

    Declaration

    Swift

    public func randomDate (between startDate:NSDate, and endDate:NSDate) -> NSDate
  • Randomly chooses an item from the given array and returns it.

    Declaration

    Swift

    public func chooseRandomly <T> (arr:[T]) -> T
  • The identity function. Returns its argument.

    Declaration

    Swift

    public func id <T> (arg:T) -> T
  • Returns a function that always returns arg, regardless of what argument is passed into it.

    Declaration

    Swift

    public func constant <T, U> (arg:T) -> (U -> T)
  • Returns the first element of collection or nil if collection is empty.

    Declaration

    Swift

    public func head
        <C: CollectionType>
        (collection: C) -> C.Generator.Element?
  • Returns a collection containing all but the first element of collection.

    Declaration

    Swift

    public func tail
        <C: CollectionType, D: RangeReplaceableCollectionType where C.Generator.Element == D.Generator.Element>
        (collection: C) -> D
  • Returns a collection containing all but the first n elements of collection.

    Declaration

    Swift

    public func tail
        <C: CollectionType, D: RangeReplaceableCollectionType where C.Generator.Element == D.Generator.Element>
        (collection: C, n: C.Index) -> D
  • Simple syntax sugar for the SequenceOf constructor, because constructors can’t be curried (yet). Wraps the given collection in a type-erased sequence.

    Declaration

    Swift

    public func toSequence <C: CollectionType>
        (collection: C) -> AnySequence<C.Generator.Element>
  • Simple syntax sugar for the GeneratorSequence constructor, because constructors can’t be curried (yet). Wraps the given generator in a type-erased sequence.

    For example:

    for x in someGenerator |> toSequence {
         // ...
    }
    

    Declaration

    Swift

    public func toSequence <G: GeneratorType>
        (generator: G) -> GeneratorSequence<G>
  • Collects a sequence (SequenceType) into a collection (ExtensibleCollectionType). The specific type of collection you want returned must be made obvious to the type-checker.

    For example:

    let seq: SequenceOf<User> = ...
    let array: [User] = seq |> toCollection
    

    Declaration

    Swift

    public func toCollection
        <S: SequenceType, D: RangeReplaceableCollectionType where S.Generator.Element == D.Generator.Element>
        (seq:S) -> D
  • Simply calls Array(collection) — however, because constructors cannot be applied like normal functions, this is more convenient in functional pipelines.

    Declaration

    Swift

    public func toArray <S: SequenceType>
        (seq:S) -> [S.Generator.Element]
  • Simply calls Array(collection) — however, because constructors cannot be applied like normal functions, this is more convenient in functional pipelines.

    Declaration

    Swift

    public func toArray <C: CollectionType>
        (collection:C) -> [C.Generator.Element]
  • Simply calls Set(collection) — however, because constructors cannot be applied like normal functions, this is more convenient in functional pipelines.

    Declaration

    Swift

    public func toSet
        <C: CollectionType>
        (collection:C) -> Set<C.Generator.Element>
  • Returns true iff one.0 == two.0 and one.1 == two.1.

    Declaration

    Swift

    public func equalTuples
        <T: Equatable, U: Equatable>
        (one: (T, U), two: (T, U)) -> Bool
  • Returns true iff the corresponding elements of sequences one and two all satisfy the provided equality predicate.

    Declaration

    Swift

    public func equalSequences
        <S: SequenceType, T: SequenceType>
        (one:S, _ two:T, _ equality:(S.Generator.Element, T.Generator.Element) -> Bool) -> Bool
  • If both of the arguments passed to both() are non-nil, it returns its arguments as a tuple (wrapped in an Optional). Otherwise, it returns nil.

    Declaration

    Swift

    public func both
        <T, U>
        (one:T?, _ two:U?) -> (T, U)?
  • If any of the elements of seq satisfy predicate, any() returns true. Otherwise, it returns false.

    Declaration

    Swift

    public func any
        <S: SequenceType>
        (predicate: S.Generator.Element -> Bool) (_ seq: S) -> Bool
  • If all of the elements of seq satisfy predicate, all() returns true. Otherwise, it returns false.

    Declaration

    Swift

    public func all
        <S: SequenceType>
        (predicate: S.Generator.Element -> Bool) (_ seq: S) -> Bool
  • If all of the arguments passed to all() are non-nil, it returns its arguments as a tuple (wrapped in an Optional). Otherwise, it returns nil.

    Declaration

    Swift

    public func all
        <T, U, V>
        (one:T?, two:U?, three:V?) -> (T, U, V)?
  • If all of the arguments passed to all() are non-nil, it returns its arguments as a tuple (wrapped in an Optional). Otherwise, it returns nil.

    Declaration

    Swift

    public func all
        <T, U, V, W>
        (one:T?, two:U?, three:V?, four:W?) -> (T, U, V, W)?
  • Curried function that returns its arguments zipped together into a 2-tuple.

    Declaration

    Swift

    public func zip2 <T, U> (one:T) (two:U) -> (T, U)
  • Curried function that returns its arguments zipped together into a 3-tuple.

    Declaration

    Swift

    public func zip3 <T, U, V>  (one:T) (two:U) (three:V) -> (T, U, V)
  • Merges the provided sequences into a sequence of tuples containing their respective elements.

    Declaration

    Swift

    public func zipseq
        <S: SequenceType, T: SequenceType>
        (one:S, _ two:T) -> AnySequence<(S.Generator.Element, T.Generator.Element)>
  • Eagerly creates a sequence out of a generator by calling the generator’s next() method until it returns nil. Do not call this on an infinite sequence.

    Declaration

    Swift

    public func unfoldGenerator <G: GeneratorType> (gen:G) -> AnySequence<G.Element>

    Return Value

    A sequence containing the elements returned by the generator.

  • Creates a new sequence using an initial value and a generator closure. The closure is called repeatedly to obtain the elements of the sequence. The sequence is returned as soon as the closure returns nil.

    Declaration

    Swift

    public func unfold <T, U>
        (closure: T -> (U, T)?) (initial:T) -> AnySequence<U>

    Parameters

    closure

    The closure takes as its only argument the T value it returned on its last iteration. It should return either nil (if the unfolding should stop), or a 2-tuple (U, T) where the first element is a new element of the sequence, and the second element is thevalue to pass to closure on the next iteration.

    initial

    The value to pass to closure the first time it’s called.

  • Very abstractly represents an iterative process that builds up a sequence.

    Calls closure on initial (and afterwards, always on the previous return value of closure) and stops after count iterations.

    The returned sequence is built up out of the left element of the tuple returned by closure. The right element of the tuple returned by closure is intended for passing state to the next iteration.

    Declaration

    Swift

    public func unfold <T, U>
        (count: Int, closure: T -> (U, T)?) (initial: T) -> AnySequence<U>

    Return Value

    A sequence containing the left/first element of each tuple returned by closure.

  • Declaration

    Swift

    public func partition
        <S: SequenceType, T where T == S.Generator.Element>
        (predicate:T -> Bool) (_ seq:S) -> (Array<T>, Array<T>)
  • Returns true iff range contains only valid indices of collection.

    Declaration

    Swift

    public func containsIndices
        <I: Comparable, C: CollectionType where I == C.Index>
        (collection: C, _ range: Range<I>) -> Bool
  • Applies transform to the first element of tuple and returns the resulting tuple.

    Declaration

    Swift

    public func mapLeft1
        <T, U, V>
        (transform: T -> V) (_ tuple: (T, U)) -> (V, U)
  • Applies transform to the key of each element of dict and returns the resulting sequence of key-value tuples as an Array. If you need a dictionary instead of a tuple array, simply pass the return value of this function through mapDictionary { $0 }.

    Declaration

    Swift

    public func mapLeft
        <T, U, V>
        (transform: T -> V) (_ dict: [T: U]) -> [(V, U)]
  • Applies transform to the first (0th) element of each tuple in seq and returns the resulting Array of tuples.

    Declaration

    Swift

    public func mapLeft
        <T, U, V>
        (transform: T -> V) (_ seq: [(T, U)]) -> [(V, U)]
  • Undocumented

  • Applies transform to the value of each key-value pair in dict, transforms the pairs into tuples, and returns the resulting Array of tuples.

    Declaration

    Swift

    public func mapRight
        <T, U, V>
        (transform: U -> V) (_ dict: [T: U]) -> [(T, V)]
  • Applies transform to the second element of each 2-tuple in seq and returns the resulting Array of tuples.

    Declaration

    Swift

    public func mapRight
        <T, U, V>
        (transform: U -> V) (_ seq:[(T, U)]) -> [(T, V)]
  • Undocumented

  • Undocumented

  • Undocumented

  • I wish my LIFE had a makeRight() function

    Declaration

    Swift

    public func makeRight
        <T, U>
        (transform:T -> U) (_ value:T) -> (T, U)
  • Undocumented

  • Undocumented

  • First element of the sequence.

    Declaration

    Swift

    public func takeFirst <S: SequenceType>
        (seq:S) -> S.Generator.Element?

    Return Value

    First element of the sequence if present

  • Checks if call returns true for any element of seq.

    Declaration

    Swift

    public func any <S: SequenceType>
        (predicate: S.Generator.Element -> Bool) (seq: S) -> Bool

    Parameters

    call

    Function to call for each element

    Return Value

    True if call returns true for any element of self

  • Subsequence from n to the end of the sequence.

    Declaration

    Swift

    public func skip <S: SequenceType>
        (n: Int) (seq: S) -> AnySequence<S.Generator.Element>

    Parameters

    n

    Number of elements to skip

    Return Value

    Sequence from n to the end

  • Object at the specified index if exists.

    Declaration

    Swift

    public func takeIndex <S: SequenceType>
        (index: Int) (seq: S) -> S.Generator.Element?

    Parameters

    index

    Return Value

    Object at index in sequence, nil if index is out of bounds

  • Skips the elements in the sequence up until the condition returns false.

    Declaration

    Swift

    public func skipWhile <S: SequenceType>
        (condition: S.Generator.Element -> Bool) (_ seq: S) -> AnySequence<S.Generator.Element>

    Parameters

    condition

    A function which returns a boolean if an element satisfies a given condition or not.

    seq

    The sequence.

    Return Value

    Elements of the sequence starting with the element which does not meet the condition.

  • Returns the elements of the sequence up until an element does not meet the condition.

    Declaration

    Swift

    public func takeWhile <S: SequenceType>
        (predicate: S.Generator.Element -> Bool) (_ seq: S) -> AnySequence<S.Generator.Element>

    Parameters

    condition

    A function which returns a boolean if an element satisfies a given condition or not.

    seq

    The sequence.

    Return Value

    Elements of the sequence up until an element does not meet the condition.

  • Undocumented

  • Takes the first n elements of seq.

    Declaration

    Swift

    public func take <S: SequenceType>
        (n: Int) (_ seq: S) -> AnySequence<S.Generator.Element>
  • Undocumented

  • Undocumented

  • Argument-reversed, curried version of reduce().

    Declaration

    Swift

    public func reducer
        <S: SequenceType, U>
        (initial:U, combine: (U, S.Generator.Element) -> U) (_ seq:S) -> U
  • Returns an array containing only the unique elements of seq.

    Declaration

    Swift

    public func unique
        <S: SequenceType where S.Generator.Element: Hashable>
        (seq:S) -> [S.Generator.Element]
  • Curries a binary function.

    Declaration

    Swift

    public func curry <A, B, R>
        (f: (A, B) -> R) -> A -> B -> R
  • Curries a ternary function.

    Declaration

    Swift

    public func curry <A, B, C, R>
        (f: (A, B, C) -> R) -> A -> B -> C -> R
  • Curries a binary function and swaps the placement of the arguments. Useful for bringing the Swift built-in collection functions into functional pipelines.

    For example:

    someArray |> currySwap(map)({ $0 ... })
    

    See also the operator, which is equivalent and more concise:

    someArray |> mapTo { $0 ... })
    

    Declaration

    Swift

    public func currySwap
        <T, U, V>
        (f: (T, U) -> V) -> U -> T -> V
  • Returns true if value is nil, false otherwise.

    Declaration

    Swift

    public func isNil <T: AnyObject> (val:T?) -> Bool
  • Returns true if value is nil, false otherwise.

    Declaration

    Swift

    public func isNil <T: NilLiteralConvertible> (val:T?) -> Bool
  • Returns true if value is nil, false otherwise.

    Declaration

    Swift

    public func isNil <T> (val:T?) -> Bool
  • Returns true if value is non-nil, false otherwise.

    Declaration

    Swift

    public func nonNil <T> (value:T?) -> Bool
  • Curried function that maps a transform function over a given object and returns a 2-tuple of the form (object, transformedObject).

    Declaration

    Swift

    public func zipMap <T, U>
        (transform: T -> U) (object: T) -> (T, U)
  • Curried function that maps transform over object and returns an unlabeled 2-tuple of the form (transformedObject, object).

    Declaration

    Swift

    public func zipMapLeft
        <T, U>
        (transform: T -> U) (object: T) -> (U, T)
  • Curried function that maps a transform function over a CollectionType and returns an array of 2-tuples of the form (object, transformedObject). If transform returns nil for a given element in the collection, the tuple for that element will not be included in the returned Array.

    Declaration

    Swift

    public func zipFilter
        <C: CollectionType, T>
        (transform: C.Generator.Element -> T?) (source: C) -> [(C.Generator.Element, T)]
  • Curried function that maps a transform function over a given object and returns an Optional 2-tuple of the form (object, transformedObject). If transform returns nil, this function will also return nil.

    Declaration

    Swift

    public func zipFilter <T, U> (transform: T -> U?) (object: T) -> (T, U)?
  • Curried function that maps a transform function over a CollectionType and returns an Array of 2-tuples of the form (object, transformedObject).

    Declaration

    Swift

    public func zipMap <C: CollectionType, T> (transform: C.Generator.Element -> T) (source: C) -> [(C.Generator.Element, T)]
  • Curried function that maps a transform function over a CollectionType and returns an Array of 2-tuples of the form (object, transformedObject).

    Declaration

    Swift

    public func zipMapLeft
        <C: CollectionType, T>
        (transform: C.Generator.Element -> T) (source: C) -> [(T, C.Generator.Element)]
  • Decomposes a Dictionary into a lazy sequence of key-value tuples.

    Declaration

    Swift

    public func pairs <K: Hashable, V>
        (dict:[K: V]) -> LazySequence<AnySequence<(K, V)>>
  • A curried, argument-reversed version of filter for use in functional pipelines. The return type must be explicitly specified, as this function is capable of returning any ExtensibleCollectionType.

    Declaration

    Swift

    public func selectWhere
        <S: SequenceType, D: RangeReplaceableCollectionType where S.Generator.Element == D.Generator.Element>
        (predicate: S.Generator.Element -> Bool) (_ seq: S) -> D

    Return Value

    A collection of type D containing the elements of seq that satisfied predicate.

  • A curried, argument-reversed version of filter for use in functional pipelines.

    Declaration

    Swift

    public func selectArray <S: SequenceType>
        (predicate: S.Generator.Element -> Bool) (_ seq: S) -> Array<S.Generator.Element>

    Return Value

    An Array containing the elements of seq that satisfied predicate.

  • A curried, argument-reversed version of filter for use in functional pipelines.

    Declaration

    Swift

    public func selectWhere <K, V> (predicate: (K, V) -> Bool) (dict: [K: V]) -> [K: V]
  • Undocumented

  • A curried, argument-reversed version of map for use in functional pipelines. For example:

    let descriptions = someCollection |> mapTo { $0.description }
    

    :param: transform The transformation function to apply to each incoming element. :param: source The collection to transform. :returns: The transformed collection.

    Declaration

    Swift

    public func mapTo
        <S: SequenceType, T>
        (transform: S.Generator.Element -> T) (source: S) -> [T]
  • Curried function that maps a transform function over a sequence and filters nil values from the resulting collection before returning it. Note that you must specify the generic parameter D (the return type) explicitly. Small pain in the ass for the lazy, but it lets you ask for any kind of ExtensibleCollectionType that you could possibly want.

    Declaration

    Swift

    public func mapFilter
        <S: SequenceType, D: RangeReplaceableCollectionType>
        (transform: S.Generator.Element -> D.Generator.Element?) (source: S) -> D

    Parameters

    transform

    The transform function.

    source

    The sequence to map.

    Return Value

    An ExtensibleCollectionType of your choosing.

  • Curried function that maps a transform function over a sequence and filters nil values from the resulting Array before returning it.

    Declaration

    Swift

    public func mapFilter
        <S: SequenceType, T>
        (transform: S.Generator.Element -> T?) (source: S) -> [T]

    Parameters

    transform

    The transform function.

    source

    The sequence to map.

    Return Value

    An Array with the mapped, non-nil values from the input sequence.

  • Curried function that rejects elements from source if they satisfy predicate. The filtered sequence is returned as an Array.

    Declaration

    Swift

    public func rejectIf
        <S: SequenceType, T where S.Generator.Element == T>
        (predicate:T -> Bool) (source: S) -> [T]
  • Curried function that rejects values from source if they satisfy predicate. Any time a value is rejected, disposal(value) is called. The filtered sequence is returned as an Array. This function is mainly useful for logging failures in functional pipelines.

    Declaration

    Swift

    public func rejectIfAndDispose
        <S: SequenceType, T where S.Generator.Element == T>
        (predicate:T -> Bool) (_ disposal:T -> Void) (source: S) -> [T]

    Parameters

    predicate

    The predicate closure to which each sequence element is passed.

    disposal

    The disposal closure that is invoked with each rejected element.

    source

    The sequence to filter.

    Return Value

    The filtered sequence as an Array.

  • A curried, argument-reversed version of each used to create side-effects in functional pipelines. Note that it returns the collection, source, unmodified. This is to facilitate fluent chaining of such pipelines. For example:

    someCollection |> doEach { println("the object is \($0)") }
                   |> mapTo    { $0.description }
                   |> doEach { println("the object's description is \($0)") }
    

    Declaration

    Swift

    public func doEach
        <S: SequenceType, T>
        (closure: S.Generator.Element -> T) (source: S) -> S

    Parameters

    transform

    The transformation function to apply to each incoming element.

    source

    The collection to transform.

    Return Value

    The collection, unmodified.

  • Invokes a closure containing side effects, ignores the return value of closure, and returns the value of its argument data.

    Declaration

    Swift

    public func doSide
        <T, X>
        (closure: T -> X) (data: T) -> T
  • Invokes a closure containing side effects, ignores the return value of closure, and returns the value of its argument data.

    Declaration

    Swift

    public func doSide2
        <T, U, X>
        (closure: (T, U) -> X) (one:T, two:U) -> (T, U)
  • Invokes a closure containing side effects, ignores the return value of closure, and returns the value of its argument data.

    Declaration

    Swift

    public func doSide3
        <T, U, V, X>
        (closure: (T, U, V) -> X) (one:T, two:U, three:V) -> (T, U, V)
  • Rejects nil elements from the provided collection.

    Declaration

    Swift

    public func rejectNil
        <T>
        (collection: [T?]) -> [T]

    Parameters

    collection

    The collection to filter.

    Return Value

    The collection with all nil elements removed.

  • Returns nil if either value in the provided 2-tuple is nil. Otherwise, returns the input tuple with its inner Optionals flattened (in other words, the returned tuple is guaranteed by the type-checker to have non-nil elements). Another way to think about rejectEitherNil is that it is a logical transform that moves the ? (Optional unary operator) from inside the tuple braces to the outside.

    Declaration

    Swift

    public func rejectEitherNil
        <T, U>
        (tuple: (T?, U?)) -> (T, U)?

    Parameters

    tuple

    The tuple to examine.

    Return Value

    The tuple or nil.

  • Rejects tuple elements from the provided collection if either value in the tuple is nil. This is often useful when handling the results of multiple subtasks when those results are provided as a Dictionary. Such a Dictionary can be passed through pairs() to create a sequence of key-value tuples that this function can be mapFiltered over.

    Declaration

    Swift

    public func rejectEitherNil
        <T, U>
        (collection: [(T?, U?)]) -> [(T, U)]

    Parameters

    collection

    The collection to filter.

    Return Value

    The provided collection with all tuples containing a nil element removed.

  • Converts the array to a dictionary with the keys supplied via keySelector.

    Declaration

    Swift

    public func mapToDictionaryKeys
        <K: Hashable, S: SequenceType>
        (keySelector:S.Generator.Element -> K) (_ seq:S) -> [K: S.Generator.Element]

    Parameters

    keySelector

    A function taking an element of array and returning the key for that element in the returned dictionary.

    Return Value

    A dictionary comprising the key-value pairs constructed by applying keySelector to the values in array.

  • Converts the array to a dictionary with the keys supplied via keySelector.

    Declaration

    Swift

    public func mapToDictionary
        <K: Hashable, V, S: SequenceType>
        (transform: S.Generator.Element -> (K, V)) (_ seq: S) -> [K: V]

    Parameters

    keySelector

    A function taking an element of array and returning the key for that element in the returned dictionary.

    Return Value

    A dictionary comprising the key-value pairs constructed by applying keySelector to the values in array.

  • Iterates through domain and returns the index of the first element for which predicate(element) returns true.

    Declaration

    Swift

    public func findWhere
        <C: CollectionType>
        (domain: C, predicate: (C.Generator.Element) -> Bool) -> C.Index?

    Parameters

    domain

    The collection to search.

    Return Value

    The index of the first matching item, or nil if none was found.

  • Decomposes array into a 2-tuple whose head property is the first element of array and whose tail property is an array containing all but the first element of array. If array.count == 0, this function returns nil.

    Declaration

    Swift

    public func decompose <T>
        (array:[T]) -> (head: T, tail: [T])?
  • Attempts to descend through a nested tree of Dictionary objects to the value represented by keypath.

    Declaration

    Swift

    public func valueForKeypath <K: Hashable, V>
        (dictionary:[K: V], keypath:[K]) -> V?
  • Attempts to descend through a nested tree of Dictionary objects to set the value of the key represented by keypath. If a non-Dictionary type is encountered before reaching the end of keypath, a .Failure is returned. Note: this function returns the result of modifying the input Dictionary in this way; it does not modify dict in place.

    Declaration

    Swift

    public func setValueForKeypath
        (var dict:[String: AnyObject], keypath:[String], value: AnyObject?) -> Result<[String: AnyObject], ErrorIO>
  • Undocumented

  • Undocumented

  • Returns a random Float value between min and max (inclusive).

    Declaration

    Swift

    public func random(min: Float = 0, max: Float) -> Float

    Parameters

    min
    max

    Return Value

    Random number

  • Undocumented

  • This function simply calls result.isSuccess() but is more convenient in functional pipelines.

    Declaration

    Swift

    public func isSuccess <T, E> (result:Result<T, E>) -> Bool
  • This function simply calls !result.isSuccess() but is more convenient in functional pipelines.

    Declaration

    Swift

    public func isFailure <T, E> (result:Result<T, E>) -> Bool
  • This function simply calls result.value() but is more convenient in functional pipelines.

    Declaration

    Swift

    public func unwrapValue <T, E> (result: Result<T, E>) -> T?
  • This function simply calls result.error() but is more convenient in functional pipelines.

    Declaration

    Swift

    public func unwrapError <T, E> (result: Result<T, E>) -> E?
  • Undocumented

  • Undocumented

  • Undocumented

  • Undocumented

  • Undocumented

  • Undocumented

  • Construct a Result using a block which receives an error parameter. Expected to return non-nil for success.

    Declaration

    Swift

    public func `try`<T>(f: (NSErrorPointer -> T?), file: String = __FILE__, line: Int = __LINE__) -> Result<T,NSError>
  • Undocumented

  • Failure coalescing .Success(Box(42)) ?? 0 ==> 42 .Failure(NSError()) ?? 0 ==> 0

    See more

    Declaration

    Swift

    public func ??<T,E>(result: Result<T,E>, @autoclosure defaultValue:  () -> T) -> T
  • Equatable Equality for Result is defined by the equality of the contained types

    See more

    Declaration

    Swift

    public func ==<T, E where T: Equatable, E: Equatable>(lhs: Result<T, E>, rhs: Result<T, E>) -> Bool
  • Undocumented

  • Returns str.characters.count

    Declaration

    Swift

    public func characterCount (str:String) -> Int
  • Converts its argument to a String.

    Declaration

    Swift

    public func stringify <T> (something:T) -> String
  • Argument-reversed, curried version of split().

    Declaration

    Swift

    public func splitOn
        <S: SequenceType where S.Generator.Element == String>
        (separator: String) (elements: S) -> [AnySequence<String>]
  • Curried version of join().

    Declaration

    Swift

    public func joinWith
        <S: SequenceType where S.Generator.Element == String>
        (separator: String) (elements: S) -> String
  • Splits the input string at every newline and returns the array of lines.

    Declaration

    Swift

    public func lines (str:String) -> [String]
  • Convenience function that calls Swift.dump(value, &x) and returns x.

    Declaration

    Swift

    public func dumpString<T>(value:T) -> String
  • Pads the end of a string to the given length with the given padding string.

    Declaration

    Swift

    public func pad (string:String, length:Int, padding:String) -> String

    Parameters

    string

    The input string to pad.

    length

    The length to which the string should be padded.

    padding

    The string to use as padding.

    Return Value

    The padded String.

  • Pads the beginning of a string to the given length with the given padding string.

    Declaration

    Swift

    public func padFront (string:String, length:Int, padding:String) -> String

    Parameters

    string

    The input string to pad.

    length

    The length to which the string should be padded.

    padding

    The string to use as padding.

    Return Value

    The padded String.

  • Pads a string to the given length using a space as the padding character.

    Declaration

    Swift

    public func pad (string:String, _ length:Int) -> String

    Parameters

    string

    The input string to pad.

    length

    The length to which the string should be padded.

    Return Value

    The padded String.

  • Undocumented

  • Pads the strings in strings to the same length using a space as the padding character.

    Declaration

    Swift

    public func padToSameLength <S: SequenceType where S.Generator.Element == String> (strings:S) -> [String]

    Parameters

    strings

    The array of strings to pad.

    Return Value

    An array containing the padded Strings.

  • Pads the String keys of strings to the same length using a space as the padding character. This is mainly useful as a console output formatting utility.

    Declaration

    Swift

    public func padKeysToSameLength <V> (dict: [String: V]) -> [String: V]

    Parameters

    dict

    The dictionary whose keys should be padded.

    Return Value

    A new dictionary with padded keys.

  • Returns the substring in string from index to the last character.

    Declaration

    Swift

    public func substringFromIndex (index:Int) (string:String) -> String
  • Returns the substring in string from the first character to index.

    Declaration

    Swift

    public func substringToIndex (index:Int) (string:String) -> String
  • Returns a string containing a pretty-printed representation of array.

    Declaration

    Swift

    public func describe <T> (array:[T]) -> String
  • Returns a string containing a pretty-printed representation of array created by mapping formatElement over its elements.

    Declaration

    Swift

    public func describe <T> (array:[T], formatElement:(T) -> String) -> String
  • Returns a string containing a pretty-printed representation of dict.

    Declaration

    Swift

    public func describe <K, V> (dict:[K: V]) -> String
  • Returns a string containing a pretty-printed representation of dict created by mapping formatClosure over its elements.

    Declaration

    Swift

    public func describe <K, V> (dict:[K: V], formatClosure:(K, V) -> String) -> String
  • Splits string into lines, adds four spaces to the beginning of each line, and then joins the lines into a single string again (preserving the original newlines).

    Declaration

    Swift

    public func indent(string:String) -> String
  • Removes whitespace (including newlines) from the beginning and end of str.

    Declaration

    Swift

    public func trim(str:String) -> String
  • Removes whitespace (including newlines) from the beginning and end of str.

    Declaration

    Swift

    public func trim
        <S: SequenceType where S.Generator.Element == Character>
        (str:S) -> String
  • Undocumented

  • Generates an rgba tuple from a hex color string.

    Declaration

    Swift

    public func rgbaFromHexCode(hex:String) -> (r:UInt32, g:UInt32, b:UInt32, a:UInt32)?

    Parameters

    hex

    The hex color string from which to create the color object. ’#’ sign is optional.

  • Given a palette of n colors and a tuple (r, g, b, a) of UInt32s, this function will return a tuple (r/n, g/n, b/n, a/n)

    Declaration

    Swift

    public func normalizeRGBA (colors c:UInt32) (r:UInt32, g:UInt32, b:UInt32, a:UInt32) -> (r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat)
  • Attempts to interpret str as a hexadecimal integer. If this succeeds, the integer is returned as a UInt32.

    Declaration

    Swift

    public func readHexInt (str:String) -> UInt32?
  • Attempts to interpret string as an rgba string of the form: rgba(1.0, 0.2, 0.3, 0.4).
    The values are interpreted as CGFloats from 0.0 to 1.0.

    Declaration

    Swift

    public func rgbaFromRGBAString (string:String) -> (r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat)?
  • Equivalent to the Unix basename command. Returns the last path component of path.

    Declaration

    Swift

    public func basename(path:String) -> String
  • Equivalent to the Unix extname command. Returns the path extension of path.

    Declaration

    Swift

    public func extname(path:String) -> String
  • Equivalent to the Unix dirname command. Returns the parent directory of the file or directory residing at path.

    Declaration

    Swift

    public func dirname(path:String) -> String
  • Returns an array of the individual components of path. The path separator is assumed to be /, as Swift currently only runs on OSX/iOS.

    Declaration

    Swift

    public func pathComponents(path:String) -> [String]
  • Returns the relative path (from -> to).

    Declaration

    Swift

    public func relativePath(from from:String, to:String) -> String
  • The set-if-non-nil operator. Will only set lhs to rhs if rhs is non-nil.

    See more

    Declaration

    Swift

    public func =?? <T>(inout lhs:T, maybeRhs: T?)
  • The set-if-non-nil operator. Will only set lhs to rhs if rhs is non-nil.

    See more

    Declaration

    Swift

    public func =?? <T>(inout lhs:T?, maybeRhs: T?)
  • The set-if-non-failure operator. Will only set lhs to rhs if rhs is not a Result<T>.Failure.

    See more

    Declaration

    Swift

    public func =?? <T, E: ErrorType> (inout lhs:T, result: Result<T, E>)
  • The set-if-non-failure operator. Will only set lhs to rhs if rhs is not a Result<T>.Failure.

    See more

    Declaration

    Swift

    public func =?? <T, E: ErrorType> (inout lhs:T?, result: Result<T, E>)
  • The initialize-if-nil operator. Will only set lhs to rhs if lhs is nil.

    See more

    Declaration

    Swift

    public func ??= <T: Any> (inout lhs:T?, @autoclosure rhs: () -> T)
  • The initialize-if-nil operator. Will only set lhs to rhs if lhs is nil.

    See more

    Declaration

    Swift

    public func ??= <T: Any> (inout lhs:T?, @autoclosure rhs: () -> T?)
  • Nil coalescing operator for Result<T, E>.

    See more

    Declaration

    Swift

    public func ?± <T, E: ErrorType>
        (lhs: T?, @autoclosure rhs: () -> Result<T, E>) -> Result<T, E>
  • Undocumented

  • Undocumented

    See more
  • The pipe-forward operator.

    See more

    Declaration

    Swift

    public func |>
        <T, U>
        (t: T, f: T -> U)
        -> U
  • The pipe-backward operator.

    See more

    Declaration

    Swift

    public func <|
        <T, U>
        (f: T -> U, t: T)
        -> U
  • Returns the left-to-right composition of unary g on unary f.

    This is the function such that (f >>> g)(x) = g(f(x)).

    See more

    Declaration

    Swift

    public func >>> <T, U, V> (f: T -> U, g: U -> V) -> T -> V
  • Returns the left-to-right composition of unary g on binary f.

    This is the function such that (f >>> g)(x, y) = g(f(x, y)).

    See more

    Declaration

    Swift

    public func >>> <T, U, V, W> (f: (T, U) -> V, g: V -> W) -> (T, U) -> W
  • Returns the left-to-right composition of binary g on unary f.

    This is the function such that (f >>> g)(x, y) = g(f(x), y).

    See more

    Declaration

    Swift

    public func >>> <T, U, V, W> (f: T -> U, g: (U, V) -> W) -> (T, V) -> W
  • Undocumented

  • Undocumented

  • Undocumented

  • Undocumented

  • Undocumented

  • The function composition operator.

    See more

    Declaration

    Swift

    public func 
        <T, U, V>
        (g: U -> V, f: T -> U)
        -> T -> V

    Parameters

    g

    The outer function, called second and passed the return value of f(x).

    f

    The inner function, called first and passed some value x.

    Return Value

    A function that takes some argument x, calls g(f(x)), and returns the value.