mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Generalize Vertex construction to arbitrary sequences.
This commit is contained in:
parent
ece5c942d5
commit
8178904a36
@ -34,10 +34,12 @@ public enum Vertex<Element> {
|
||||
}
|
||||
|
||||
|
||||
public init<A, B>(rows: Stream<A>, columns: Stream<B>, combine: (A, B) -> Element) {
|
||||
public init<S1: SequenceType, S2: SequenceType>(rows: S1, columns: S2, combine: (S1.Generator.Element, S2.Generator.Element) -> Element) {
|
||||
let rows = Stream(sequence: rows)
|
||||
let columns = Stream(sequence: columns)
|
||||
self = columns
|
||||
.map { b in rows.map { a in (a, b) } }
|
||||
.fold(Vertex<(A, B)>.End) {
|
||||
.fold(Vertex<(S1.Generator.Element, S2.Generator.Element)>.End) {
|
||||
$0.fold(($1, .End)) {
|
||||
($1.flatMap { row, _ in row }.flatMap { $0.right }, .XY($0, $1.map { _, column in column }, $1.flatMap { row, _ in row }))
|
||||
}.1
|
||||
|
Loading…
Reference in New Issue
Block a user