This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [D std.range.chain]: http://dlang.org/phobos/std_range.html#chain | |
/// Concatenates several sequences of same kind into a single one. | |
public func chain<S : SequenceType>(sequences: S...) -> SequenceOf<S.Generator.Element> { | |
return SequenceOf {_ -> GeneratorOf<S.Generator.Element> in | |
var ss = sequences.generate() | |
var g = ss.next()?.generate() | |
return GeneratorOf { | |
if let x = g?.next() { return x } | |
// Must be `while let` not `if let` to handle empty sequence in between |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// accumulate (scanl) | |
public func accumulate<S : SequenceType, T> | |
(sequence: S, initial: T, combine: (T, S.Generator.Element)->T) | |
-> SequenceOf<T> | |
{ | |
return SequenceOf {_ -> GeneratorOf<T> in | |
var g = sequence.generate() | |
var value:T? = initial | |
return GeneratorOf { | |
switch value { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Accelerate.vecLib.vForce | |
// Convenience functions wrapping functions from vForce.h. | |
// | |
// Function names are orignal name without `vv` prefix with few exceptions listed below. | |
// - trunc = vvint | |
// - round = vvnint | |
// - reciprocal = vvrec | |
// | |
// Arguments are adjusted to match standard <math.h> functions when applicable. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - zip (longest) | |
// Zip sequences continue to the end of the longest sequence. | |
// Treats as if the shorter sequences have .None elements to fill the gap. | |
// MARK: ([A], [B]) -> [(A?, B?)] | |
/// Generalized zip2 longest, zipping with the given function instead of a tupling function. | |
public func zipLongest<A : SequenceType, B : SequenceType, R> | |
(sequenceA: A, sequenceB: B, with f: (A.Generator.Element?, B.Generator.Element?)->R) | |
-> SequenceOf<R> | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [roundRobin](http://dlang.org/phobos/std_range.html#roundRobin) | |
public func roundRobin<S:SequenceType>(sequences:S ...) | |
-> SequenceOf<S.Generator.Element> | |
{ | |
func isDone(gs:[S.Generator?]) -> Bool { | |
for g in gs { if (g != nil) { return false } } | |
return true | |
} | |
return SequenceOf {_ -> GeneratorOf<S.Generator.Element> in |
NewerOlder