0001
0003
0005 public extension SequenceType {
0006
0007 @warn_unused_result
0014 func interpose(element: Generator.Element) -> [Generator.Element] {
0015 var g = generate()
0016
0017 return g.next().map {
0018 var ret = [$0]
0019 while let next = g.next() {
0020 ret.append(element)
0021 ret.append(next)
0022 }
0023 return ret
0024 } ?? []
0025 }
0026
0027 @warn_unused_result
0034 func interpose(element: Generator.Element, n: Int) -> [Generator.Element] {
0035
0036 var ret: [Generator.Element] = []
0037 var g = generate()
0038 var i = n + 1
0039
0040 while let next = g.next() {
0041 if --i == 0 {
0042 ret.append(element)
0043 i = n
0044 }
0045 ret.append(next)
0046 }
0047 return ret
0048 }
0049 }
0050
0051
0053 public extension SequenceType {
0054
0055 @warn_unused_result
0063 func interpose<C : CollectionType where C.Generator.Element == Generator.Element>
0064 (col: C) -> [Generator.Element] {
0065 var g = generate()
0066 return g.next().map {
0067 var ret = [$0]
0068 while let next = g.next() {
0069 ret.appendContentsOf(col)
0070 ret.append(next)
0071 }
0072 return ret
0073 } ?? []
0074 }
0075
0076
0084 func interpose<C : CollectionType where C.Generator.Element == Generator.Element>
0085 (col: C, n: Int) -> [Generator.Element] {
0086 var g = generate()
0087 return g.next().map {
0088 var i = n
0089 var ret = [$0]
0090 while let next = g.next() {
0091 if --i == 0 {
0092 ret.appendContentsOf(col)
0093 i = n
0094 }
0095 ret.append(next)
0096 }
0097 return ret
0098 } ?? []
0099 }
0100 }
0101
0102
0104 @warn_unused_result
0111 public func interdig<
0112 S0 : SequenceType, S1 : SequenceType where
0113 S0.Generator.Element == S1.Generator.Element
0114 >(s0: S0, _ s1: S1) -> [S0.Generator.Element] {
0115
0116 var ret: [S0.Generator.Element] = []
0117
0118 var (g0, g1) = (s0.generate(), s1.generate())
0119
0120 while let e0 = g0.next(), e1 = g1.next() {
0121 ret.append(e0)
0122 ret.append(e1)
0123 }
0124
0125 return ret
0126 }
0127
0128 ParameterParameter@warn_unused_result
0138 public func interdig<
0139 S0 : SequenceType, S1 : SequenceType where
0140 S0.Generator.Element == S1.Generator.Element
0141 >(s0: S0, _ s1: S1, s0Len: Int, s1Len: Int) -> [S0.Generator.Element] {
0142
0143 var ret: [S0.Generator.Element] = []
0144
0145 var (g0, g1) = (s0.generate(), s1.generate())
0146
0147 for ;; {
0148 for _ in 0..<s0Len {
0149 if let next = g0.next() {
0150 ret.append(next)
0151 } else {
0152 return ret
0153 }
0154 }
0155 for _ in 0..<s1Len {
0156 if let next = g1.next() {
0157 ret.append(next)
0158 } else {
0159 return ret
0160 }
0161 }
0162 }
0163 }
0164
0165
0167 public struct InterposeElGenInterpose.swift:183 | private let element: InterposeElGen<S.Generator>.Element |
Interpose.swift:187 | public func generate() -> InterposeElGen<S.Generator> { |
Interpose.swift:188 | return InterposeElGen(n: n, count: n, g: seq.generate(), element: element) |
<GInterpose.swift:173 | private var g: G |
Interpose.swift:174 | private let element: G.Element |
Interpose.swift:176 | public mutating func next() -> G.Element? { |
: GeneratorType> : GeneratorType {
0170
0171 private let nInterpose.swift:177 | return --count < 0 ? {count = n; return element}() : g.next() |
: Int
0172 private var countInterpose.swift:177 | return --count < 0 ? {count = n; return element}() : g.next() |
Interpose.swift:177 | return --count < 0 ? {count = n; return element}() : g.next() |
: Int
0173 private var gInterpose.swift:177 | return --count < 0 ? {count = n; return element}() : g.next() |
: G
0174 private let elementInterpose.swift:177 | return --count < 0 ? {count = n; return element}() : g.next() |
: G.Element
0175 public mutating func next() -> G.Element? {
0177 return --count < 0 ? {count = n; return element}() : g.next()
0178 }
0179 }
0180 public struct InterposeElSeqInterpose.swift:202 | func interpose(element: Generator.Element) -> InterposeElSeq<Self> { |
Interpose.swift:203 | return InterposeElSeq(element: element, n: 1, seq: self) |
Interpose.swift:214 | func interpose(element: Generator.Element, n: Int) -> InterposeElSeq<Self> { |
Interpose.swift:215 | return InterposeElSeq(element: element, n: n, seq: self) |
<SInterpose.swift:183 | private let element: InterposeElGen<S.Generator>.Element |
Interpose.swift:185 | private let seq: S |
Interpose.swift:187 | public func generate() -> InterposeElGen<S.Generator> { |
: SequenceType> : LazySequenceType {
0182
0183 private let elementInterpose.swift:188 | return InterposeElGen(n: n, count: n, g: seq.generate(), element: element) |
: InterposeElGen<S.Generator>.Element
0184 private let nInterpose.swift:188 | return InterposeElGen(n: n, count: n, g: seq.generate(), element: element) |
Interpose.swift:188 | return InterposeElGen(n: n, count: n, g: seq.generate(), element: element) |
: Int
0185 private let seqInterpose.swift:188 | return InterposeElGen(n: n, count: n, g: seq.generate(), element: element) |
: S
0186 public func generate() -> InterposeElGen<S.Generator> {
0188 return InterposeElGen(n: n, count: n, g: seq.generate(), element: element)
0189 }
0190 }
0191
0192 public extension LazySequenceType {
0193
0194 @warn_unused_result
0202 func interpose(element: Generator.Element) -> InterposeElSeq<Self> {
0203 return InterposeElSeq(element: element, n: 1, seq: self)
0204 }
0205
0206 @warn_unused_result
0214 func interpose(element: Generator.Element, n: Int) -> InterposeElSeq<Self> {
0215 return InterposeElSeq(element: element, n: n, seq: self)
0216 }
0217 }
0218
0219 public struct InterposeColGenInterpose.swift:253 | public func generate() -> InterposeColGen<S.Generator, C> { |
Interpose.swift:254 | return InterposeColGen(col: col, g: seq.generate(), n: n, count: n + 1, colG: col.generate()) |
<
0222 GInterpose.swift:228 | private var g: G |
Interpose.swift:233 | public mutating func next() -> G.Element? { |
: GeneratorType,
0223 CInterpose.swift:227 | private let col: C |
Interpose.swift:231 | private var colG: C.Generator |
: CollectionType where
0224 G.Element == C.Generator.Element
0225 > : GeneratorType {
0226
0227 private let colInterpose.swift:237 | colG = col.generate() |
: C
0228 private var gInterpose.swift:238 | return g.next() |
Interpose.swift:239 | }()}() : g.next() |
: G
0229 private let nInterpose.swift:236 | count = n |
: Int
0230 private var countInterpose.swift:234 | return --count <= 0 ? { |
Interpose.swift:236 | count = n |
: Int
0231 private var colGInterpose.swift:235 | colG.next() ?? { |
Interpose.swift:237 | colG = col.generate() |
: C.Generator
0232 public mutating func next() -> G.Element? {
0234 return --count <= 0 ? {
0235 colG.next() ?? {
0236 count = n
0237 colG = col.generate()
0238 return g.next()
0239 }()}() : g.next()
0240 }
0241 }
0242 public struct InterposeColSeqInterpose.swift:271 | >(elements: C) -> InterposeColSeq<Self, C> { |
Interpose.swift:272 | return InterposeColSeq(col: elements, n: 1, seq: self) |
Interpose.swift:286 | >(elements: C, n: Int) -> InterposeColSeq<Self, C> { |
Interpose.swift:287 | return InterposeColSeq(col: elements, n: n, seq: self) |
<
0244 SInterpose.swift:251 | private let seq: S |
Interpose.swift:253 | public func generate() -> InterposeColGen<S.Generator, C> { |
: SequenceType,
0245 CInterpose.swift:249 | private let col: C |
Interpose.swift:253 | public func generate() -> InterposeColGen<S.Generator, C> { |
: CollectionType where
0246 S.Generator.Element == C.Generator.Element
0247 > : LazySequenceType {
0248
0249 private let colInterpose.swift:254 | return InterposeColGen(col: col, g: seq.generate(), n: n, count: n + 1, colG: col.generate()) |
Interpose.swift:254 | return InterposeColGen(col: col, g: seq.generate(), n: n, count: n + 1, colG: col.generate()) |
: C
0250 private let nInterpose.swift:254 | return InterposeColGen(col: col, g: seq.generate(), n: n, count: n + 1, colG: col.generate()) |
Interpose.swift:254 | return InterposeColGen(col: col, g: seq.generate(), n: n, count: n + 1, colG: col.generate()) |
: Int
0251 private let seqInterpose.swift:254 | return InterposeColGen(col: col, g: seq.generate(), n: n, count: n + 1, colG: col.generate()) |
: S
0252 public func generate() -> InterposeColGen<S.Generator, C> {
0254 return InterposeColGen(col: col, g: seq.generate(), n: n, count: n + 1, colG: col.generate())
0255 }
0256 }
0257
0258 public extension LazySequenceType {
0259
0260 @warn_unused_result
0268 func interpose<
0269 C: CollectionType where
0270 C.Generator.Element == Generator.Element
0271 >(elements: C) -> InterposeColSeq<Self, C> {
0272 return InterposeColSeq(col: elements, n: 1, seq: self)
0273 }
0274
0275 @warn_unused_result
0283 func interpose<
0284 C: CollectionType where
0285 C.Generator.Element == Generator.Element
0286 >(elements: C, n: Int) -> InterposeColSeq<Self, C> {
0287 return InterposeColSeq(col: elements, n: n, seq: self)
0288 }
0289 }
0290
0291 public struct InterDigGenInterpose.swift:326 | public func generate() -> InterDigGen<S0.Generator, S1.Generator> { |
Interpose.swift:327 | return InterDigGen( |
<
0294 G0Interpose.swift:299 | private var g0: G0 |
Interpose.swift:307 | public mutating func next() -> G0.Element? { |
: GeneratorType,
0295 G1Interpose.swift:300 | private var g1: G1 |
: GeneratorType where
0296 G0.Element == G1.Element
0297 > : GeneratorType {
0298
0299 private var g0Interpose.swift:309 | if count >= bN { return count < 0 ? g1.next() : g0.next() } |
: G0
0300 private var g1Interpose.swift:309 | if count >= bN { return count < 0 ? g1.next() : g0.next() } |
: G1
0301
0302 private let aNInterpose.swift:308 | for (--count;;count = aN) { |
: Int
0303 private let bNInterpose.swift:309 | if count >= bN { return count < 0 ? g1.next() : g0.next() } |
: Int
0304
0305 private var countInterpose.swift:308 | for (--count;;count = aN) { |
Interpose.swift:308 | for (--count;;count = aN) { |
Interpose.swift:309 | if count >= bN { return count < 0 ? g1.next() : g0.next() } |
Interpose.swift:309 | if count >= bN { return count < 0 ? g1.next() : g0.next() } |
: Int
0306 public mutating func next() -> G0.Element? {
0308 for (--count;;count = aN) {
0309 if count >= bN { return count < 0 ? g1.next() : g0.next() }
0310 }
0311 }
0312 }
0313 public struct InterDigSeqInterpose.swift:347 | >(s0: S0, _ s1: S1) -> InterDigSeq<S0, S1> { |
Interpose.swift:348 | return InterDigSeq(s0: s0, s1: s1, aN: 1, bN: 1) |
Interpose.swift:364 | >(s0: S0, _ s1: S1, s0Len: Int, s1Len: Int = 1) -> InterDigSeq<S0, S1> { |
Interpose.swift:365 | return InterDigSeq(s0: s0, s1: s1, aN: s0Len, bN: s1Len) |
<
0315 S0Interpose.swift:320 | private let s0: S0 |
Interpose.swift:326 | public func generate() -> InterDigGen<S0.Generator, S1.Generator> { |
: LazySequenceType,
0316 S1Interpose.swift:321 | private let s1: S1 |
Interpose.swift:326 | public func generate() -> InterDigGen<S0.Generator, S1.Generator> { |
: LazySequenceType where
0317 S0.Generator.Element == S1.Generator.Element
0318 > : LazySequenceType {
0319
0320 private let s0Interpose.swift:328 | g0: s0.generate(), |
: S0
0321 private let s1Interpose.swift:329 | g1: s1.generate(), |
: S1
0322
0323 private let aNInterpose.swift:330 | aN: aN - 1, |
Interpose.swift:332 | count: aN |
: Int
0324 private let bNInterpose.swift:331 | bN: -bN, |
: Int
0325 public func generate() -> InterDigGen<S0.Generator, S1.Generator> {
0327 return InterDigGen(
0328 g0: s0.generate(),
0329 g1: s1.generate(),
0330 aN: aN - 1,
0331 bN: -bN,
0332 count: aN
0333 )
0334 }
0335 }
0336
0337 @warn_unused_result
0344 public func interdig<
0345 S0 : LazySequenceType, S1 : LazySequenceType where
0346 S0.Generator.Element == S1.Generator.Element
0347 >(s0: S0, _ s1: S1) -> InterDigSeq<S0, S1> {
0348 return InterDigSeq(s0: s0, s1: s1, aN: 1, bN: 1)
0349 }
0350
0351 ParameterParameter@warn_unused_result
0361 public func interdig<
0362 S0 : SequenceType, S1 : SequenceType where
0363 S0.Generator.Element == S1.Generator.Element
0364 >(s0: S0, _ s1: S1, s0Len: Int, s1Len: Int = 1) -> InterDigSeq<S0, S1> {
0365 return InterDigSeq(s0: s0, s1: s1, aN: s0Len, bN: s1Len)
0366 }
0367