Functions
The following functions are available globally.
-
Undocumented
-
Undocumented
-
Undocumented
-
Undocumented
-
Undocumented
-
Simple wrapper for
dispatch_afterthat 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
startDateandendDateand 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
collectionornilifcollectionis 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
nelements ofcollection.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
SequenceOfconstructor, because constructors can’t be curried (yet). Wraps the givencollectionin a type-erased sequence.Declaration
Swift
public func toSequence <C: CollectionType> (collection: C) -> AnySequence<C.Generator.Element> -
Simple syntax sugar for the
GeneratorSequenceconstructor, because constructors can’t be curried (yet). Wraps the givengeneratorin 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 |> toCollectionDeclaration
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
trueiffone.0==two.0andone.1==two.1.Declaration
Swift
public func equalTuples <T: Equatable, U: Equatable> (one: (T, U), two: (T, U)) -> Bool -
Returns
trueiff the corresponding elements of sequencesoneandtwoall satisfy the providedequalitypredicate.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 anOptional). Otherwise, it returnsnil.Declaration
Swift
public func both <T, U> (one:T?, _ two:U?) -> (T, U)? -
If any of the elements of
seqsatisfypredicate,any()returnstrue. Otherwise, it returnsfalse.Declaration
Swift
public func any <S: SequenceType> (predicate: S.Generator.Element -> Bool) (_ seq: S) -> Bool -
If all of the elements of
seqsatisfypredicate,all()returnstrue. Otherwise, it returnsfalse.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 anOptional). Otherwise, it returnsnil.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 anOptional). Otherwise, it returnsnil.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 returnsnil. 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
closureThe closure takes as its only argument the
Tvalue it returned on its last iteration. It should return eithernil(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 toclosureon the next iteration.initialThe value to pass to
closurethe first time it’s called. -
Very abstractly represents an iterative process that builds up a sequence.
Calls
closureoninitial(and afterwards, always on the previous return value ofclosure) and stops aftercountiterations.The returned sequence is built up out of the left element of the tuple returned by
closure. The right element of the tuple returned byclosureis 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
trueiffrangecontains only valid indices ofcollection.Declaration
Swift
public func containsIndices <I: Comparable, C: CollectionType where I == C.Index> (collection: C, _ range: Range<I>) -> Bool -
Applies
transformto the first element oftupleand returns the resulting tuple.Declaration
Swift
public func mapLeft1 <T, U, V> (transform: T -> V) (_ tuple: (T, U)) -> (V, U) -
Applies
transformto the key of each element ofdictand returns the resulting sequence of key-value tuples as anArray. If you need a dictionary instead of a tuple array, simply pass the return value of this function throughmapDictionary { $0 }.Declaration
Swift
public func mapLeft <T, U, V> (transform: T -> V) (_ dict: [T: U]) -> [(V, U)] -
Applies
transformto the first (0th) element of each tuple inseqand returns the resultingArrayof tuples.Declaration
Swift
public func mapLeft <T, U, V> (transform: T -> V) (_ seq: [(T, U)]) -> [(V, U)] -
Undocumented
-
Applies
transformto the value of each key-value pair indict, transforms the pairs into tuples, and returns the resultingArrayof tuples.Declaration
Swift
public func mapRight <T, U, V> (transform: U -> V) (_ dict: [T: U]) -> [(T, V)] -
Applies
transformto the second element of each 2-tuple inseqand returns the resultingArrayof 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()
functionDeclaration
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) -> BoolParameters
callFunction to call for each element
Return Value
True if call returns true for any element of self
-
Subsequence from
nto the end of the sequence.Declaration
Swift
public func skip <S: SequenceType> (n: Int) (seq: S) -> AnySequence<S.Generator.Element>Parameters
nNumber 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
indexReturn Value
Object at index in sequence,
nilif 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
conditionA function which returns a boolean if an element satisfies a given condition or not.
seqThe 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
conditionA function which returns a boolean if an element satisfies a given condition or not.
seqThe sequence.
Return Value
Elements of the sequence up until an element does not meet the condition.
-
Undocumented
-
Takes the first
nelements ofseq.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
trueifvalueisnil,falseotherwise.Declaration
Swift
public func isNil <T: AnyObject> (val:T?) -> Bool -
Returns
trueifvalueisnil,falseotherwise.Declaration
Swift
public func isNil <T: NilLiteralConvertible> (val:T?) -> Bool -
Returns
trueifvalueisnil,falseotherwise.Declaration
Swift
public func isNil <T> (val:T?) -> Bool -
Returns
trueifvalueis non-nil,falseotherwise.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
transformoverobjectand 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
CollectionTypeand returns an array of 2-tuples of the form(object, transformedObject). Iftransformreturnsnilfor a given element in the collection, the tuple for that element will not be included in the returnedArray.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
Optional2-tuple of the form(object, transformedObject). Iftransformreturnsnil, this function will also returnnil.Declaration
Swift
public func zipFilter <T, U> (transform: T -> U?) (object: T) -> (T, U)? -
Curried function that maps a transform function over a
CollectionTypeand returns anArrayof 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
CollectionTypeand returns anArrayof 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
Dictionaryinto 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
filterfor use in functional pipelines. The return type must be explicitly specified, as this function is capable of returning anyExtensibleCollectionType.Declaration
Swift
public func selectWhere <S: SequenceType, D: RangeReplaceableCollectionType where S.Generator.Element == D.Generator.Element> (predicate: S.Generator.Element -> Bool) (_ seq: S) -> DReturn Value
A collection of type
Dcontaining the elements ofseqthat satisfiedpredicate. -
A curried, argument-reversed version of
filterfor 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
Arraycontaining the elements ofseqthat satisfiedpredicate. -
A curried, argument-reversed version of
filterfor 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
mapfor 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 ofExtensibleCollectionTypethat you could possibly want.Declaration
Swift
public func mapFilter <S: SequenceType, D: RangeReplaceableCollectionType> (transform: S.Generator.Element -> D.Generator.Element?) (source: S) -> DParameters
transformThe transform function.
sourceThe sequence to map.
Return Value
An
ExtensibleCollectionTypeof your choosing. -
Curried function that maps a transform function over a sequence and filters
nilvalues from the resultingArraybefore returning it.Declaration
Swift
public func mapFilter <S: SequenceType, T> (transform: S.Generator.Element -> T?) (source: S) -> [T]Parameters
transformThe transform function.
sourceThe sequence to map.
Return Value
An
Arraywith the mapped, non-nil values from the input sequence. -
Curried function that rejects elements from
sourceif they satisfypredicate. The filtered sequence is returned as anArray.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
sourceif they satisfypredicate. Any time a value is rejected,disposal(value)is called. The filtered sequence is returned as anArray. 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
predicateThe predicate closure to which each sequence element is passed.
disposalThe disposal closure that is invoked with each rejected element.
sourceThe sequence to filter.
Return Value
The filtered sequence as an
Array. -
A curried, argument-reversed version of
eachused 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) -> SParameters
transformThe transformation function to apply to each incoming element.
sourceThe 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 argumentdata.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 argumentdata.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 argumentdata.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
collectionThe collection to filter.
Return Value
The collection with all
nilelements removed. -
Returns
nilif either value in the provided 2-tuple isnil. Otherwise, returns the input tuple with its innerOptionals flattened (in other words, the returned tuple is guaranteed by the type-checker to have non-nilelements). Another way to think aboutrejectEitherNilis that it is a logical transform that moves the?(Optionalunary operator) from inside the tuple braces to the outside.Declaration
Swift
public func rejectEitherNil <T, U> (tuple: (T?, U?)) -> (T, U)?Parameters
tupleThe 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 aDictionary. Such aDictionarycan be passed throughpairs()to create a sequence of key-value tuples that this function can bemapFiltered over.Declaration
Swift
public func rejectEitherNil <T, U> (collection: [(T?, U?)]) -> [(T, U)]Parameters
collectionThe collection to filter.
Return Value
The provided collection with all tuples containing a
nilelement 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
keySelectorA function taking an element of
arrayand returning the key for that element in the returned dictionary.Return Value
A dictionary comprising the key-value pairs constructed by applying
keySelectorto the values inarray. -
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
keySelectorA function taking an element of
arrayand returning the key for that element in the returned dictionary.Return Value
A dictionary comprising the key-value pairs constructed by applying
keySelectorto the values inarray. -
Iterates through
domainand returns the index of the first element for whichpredicate(element)returnstrue.Declaration
Swift
public func findWhere <C: CollectionType> (domain: C, predicate: (C.Generator.Element) -> Bool) -> C.Index?Parameters
domainThe collection to search.
Return Value
The index of the first matching item, or
nilif none was found.
-
Decomposes
arrayinto a 2-tuple whoseheadproperty is the first element ofarrayand whosetailproperty is an array containing all but the first element ofarray. Ifarray.count == 0, this function returnsnil.Declaration
Swift
public func decompose <T> (array:[T]) -> (head: T, tail: [T])? -
Attempts to descend through a nested tree of
Dictionaryobjects to the value represented bykeypath.Declaration
Swift
public func valueForKeypath <K: Hashable, V> (dictionary:[K: V], keypath:[K]) -> V? -
Attempts to descend through a nested tree of
Dictionaryobjects to set the value of the key represented bykeypath. If a non-Dictionarytype is encountered before reaching the end ofkeypath, a.Failureis returned. Note: this function returns the result of modifying the inputDictionaryin this way; it does not modifydictin 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) -> FloatParameters
minmaxReturn 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
Resultusing 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 moreDeclaration
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 moreDeclaration
Swift
public func ==<T, E where T: Equatable, E: Equatable>(lhs: Result<T, E>, rhs: Result<T, E>) -> Bool -
Undocumented
-
Undocumented
-
Returns
str.characters.countDeclaration
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 returnsx.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) -> StringParameters
stringThe input string to pad.
lengthThe length to which the string should be padded.
paddingThe 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) -> StringParameters
stringThe input string to pad.
lengthThe length to which the string should be padded.
paddingThe 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) -> StringParameters
stringThe input string to pad.
lengthThe length to which the string should be padded.
Return Value
The padded
String. -
Undocumented
-
Pads the strings in
stringsto 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
stringsThe array of strings to pad.
Return Value
An array containing the padded
Strings. -
Pads the
Stringkeys ofstringsto 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
dictThe dictionary whose keys should be padded.
Return Value
A new dictionary with padded keys.
-
Returns the substring in
stringfromindexto the last character.Declaration
Swift
public func substringFromIndex (index:Int) (string:String) -> String -
Returns the substring in
stringfrom the first character toindex.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
arraycreated by mappingformatElementover 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
dictcreated by mappingformatClosureover its elements.Declaration
Swift
public func describe <K, V> (dict:[K: V], formatClosure:(K, V) -> String) -> String -
Splits
stringinto 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
hexThe hex color string from which to create the color object. ’#’ sign is optional.
-
Given a palette of
ncolors and a tuple(r, g, b, a)ofUInt32s, 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
stras a hexadecimal integer. If this succeeds, the integer is returned as aUInt32.Declaration
Swift
public func readHexInt (str:String) -> UInt32? -
Attempts to interpret
stringas an rgba string of the form:rgba(1.0, 0.2, 0.3, 0.4).
The values are interpreted asCGFloats from0.0to1.0.Declaration
Swift
public func rgbaFromRGBAString (string:String) -> (r:CGFloat, g:CGFloat, b:CGFloat, a:CGFloat)?
-
Equivalent to the Unix
basenamecommand. Returns the last path component ofpath.Declaration
Swift
public func basename(path:String) -> String -
Equivalent to the Unix
extnamecommand. Returns the path extension ofpath.Declaration
Swift
public func extname(path:String) -> String -
Equivalent to the Unix
dirnamecommand. Returns the parent directory of the file or directory residing atpath.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
-
Undocumented
-
Undocumented
-
Undocumented
-
Undocumented
-
Undocumented
-
Undocumented
-
The set-if-non-nil operator. Will only set
See morelhstorhsifrhsis non-nil.Declaration
Swift
public func =?? <T>(inout lhs:T, maybeRhs: T?) -
The set-if-non-nil operator. Will only set
See morelhstorhsifrhsis non-nil.Declaration
Swift
public func =?? <T>(inout lhs:T?, maybeRhs: T?) -
The set-if-non-failure operator. Will only set
See morelhstorhsifrhsis not aResult<T>.Failure.Declaration
Swift
public func =?? <T, E: ErrorType> (inout lhs:T, result: Result<T, E>) -
The set-if-non-failure operator. Will only set
See morelhstorhsifrhsis not aResult<T>.Failure.Declaration
Swift
public func =?? <T, E: ErrorType> (inout lhs:T?, result: Result<T, E>) -
The initialize-if-nil operator. Will only set
See morelhstorhsiflhsis nil.Declaration
Swift
public func ??= <T: Any> (inout lhs:T?, @autoclosure rhs: () -> T) -
The initialize-if-nil operator. Will only set
See morelhstorhsiflhsis nil.Declaration
Swift
public func ??= <T: Any> (inout lhs:T?, @autoclosure rhs: () -> T?) -
Nil coalescing operator for
See moreResult<T, E>.Declaration
Swift
public func ?± <T, E: ErrorType> (lhs: T?, @autoclosure rhs: () -> Result<T, E>) -> Result<T, E> -
Undocumented
-
Undocumented
See more
-
Undocumented
-
Undocumented
-
Returns the left-to-right composition of unary
gon unaryf.This is the function such that
See more(f >>> g)(x)=g(f(x)).Declaration
Swift
public func >>> <T, U, V> (f: T -> U, g: U -> V) -> T -> V -
Returns the left-to-right composition of unary
gon binaryf.This is the function such that
See more(f >>> g)(x, y)=g(f(x, y)).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
gon unaryf.This is the function such that
See more(f >>> g)(x, y)=g(f(x), y).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 moreDeclaration
Swift
public func • <T, U, V> (g: U -> V, f: T -> U) -> T -> VParameters
gThe outer function, called second and passed the return value of f(x).
fThe 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.
View on GitHub
Functions Reference