File tree Expand file tree Collapse file tree 5 files changed +82
-8
lines changed Expand file tree Collapse file tree 5 files changed +82
-8
lines changed Original file line number Diff line number Diff line change @@ -289,3 +289,19 @@ extension Sequence {
289
289
Chain ( base1: self , base2: other)
290
290
}
291
291
}
292
+
293
+ //===----------------------------------------------------------------------===//
294
+ // lazy.chained(with:)
295
+ //===----------------------------------------------------------------------===//
296
+
297
+ extension LazySequenceProtocol {
298
+ /// Returns a new lazy sequence that iterates over this sequence, followed by
299
+ /// the given sequence.
300
+ public func chained< S: Sequence > (
301
+ with other: S
302
+ ) -> LazySequence < Chain < Elements , S > >
303
+ where Element == S . Element
304
+ {
305
+ elements. chained ( with: other) . lazy
306
+ }
307
+ }
Original file line number Diff line number Diff line change @@ -151,3 +151,17 @@ extension Collection {
151
151
return Combinations ( self , k: k)
152
152
}
153
153
}
154
+
155
+ //===----------------------------------------------------------------------===//
156
+ // lazy.combinations(count:)
157
+ //===----------------------------------------------------------------------===//
158
+
159
+ extension LazyCollectionProtocol {
160
+ /// Returns a lazy collection of combinations of this collection's elements,
161
+ /// with each combination having the specificed number of elements.
162
+ public func combinations(
163
+ ofCount k: Int
164
+ ) -> LazySequence < Combinations < Elements > > {
165
+ elements. combinations ( ofCount: k) . lazy
166
+ }
167
+ }
Original file line number Diff line number Diff line change @@ -71,13 +71,7 @@ extension Collection {
71
71
public func cycled( ) -> Cycle < Self > {
72
72
Cycle ( base: self )
73
73
}
74
- }
75
-
76
- //===----------------------------------------------------------------------===//
77
- // repeated(count:)
78
- //===----------------------------------------------------------------------===//
79
-
80
- extension Collection {
74
+
81
75
/// Returns a sequence that repeats the elements of this collection the
82
76
/// specified number of times.
83
77
///
@@ -99,3 +93,23 @@ extension Collection {
99
93
repeatElement ( self , count: times) . joined ( )
100
94
}
101
95
}
96
+
97
+ //===----------------------------------------------------------------------===//
98
+ // lazy.cycled()
99
+ //===----------------------------------------------------------------------===//
100
+
101
+ extension LazyCollection {
102
+ /// Returns a lazy sequence that repeats the elements of this collection
103
+ /// forever.
104
+ public func cycled( ) -> LazySequence < Cycle < Elements > > {
105
+ elements. cycled ( ) . lazy
106
+ }
107
+
108
+ /// Returns a lazy sequence that repeats the elements of this collection the
109
+ /// specified number of times.
110
+ public func cycled(
111
+ times: Int
112
+ ) -> LazySequence < FlattenSequence < Repeated < Elements > > > {
113
+ elements. cycled ( times: times) . lazy
114
+ }
115
+ }
Original file line number Diff line number Diff line change @@ -59,6 +59,10 @@ extension Indexed: RandomAccessCollection where Base: RandomAccessCollection {}
59
59
extension Indexed : Equatable where Base: Equatable { }
60
60
extension Indexed : Hashable where Base: Hashable { }
61
61
62
+ //===----------------------------------------------------------------------===//
63
+ // indexed()
64
+ //===----------------------------------------------------------------------===//
65
+
62
66
extension Collection {
63
67
/// Returns a collection of pairs *(i, x)*, where *i* represents an index of
64
68
/// the collection, and *x* represents an element.
@@ -79,3 +83,15 @@ extension Collection {
79
83
Indexed ( base: self )
80
84
}
81
85
}
86
+
87
+ //===----------------------------------------------------------------------===//
88
+ // lazy.indexed()
89
+ //===----------------------------------------------------------------------===//
90
+
91
+ extension LazyCollectionProtocol {
92
+ /// Returns a lazy collection of pairs *(i, x)*, where *i* represents an index
93
+ /// of the collection, and *x* represents an element.
94
+ public func indexed( ) -> LazySequence < Indexed < Elements > > {
95
+ elements. indexed ( ) . lazy
96
+ }
97
+ }
Original file line number Diff line number Diff line change @@ -177,7 +177,7 @@ extension MutableCollection
177
177
}
178
178
179
179
//===----------------------------------------------------------------------===//
180
- // permutations(count :)
180
+ // permutations(ofCount :)
181
181
//===----------------------------------------------------------------------===//
182
182
183
183
extension Collection {
@@ -234,3 +234,17 @@ extension Collection {
234
234
return Permutations ( self , k: k)
235
235
}
236
236
}
237
+
238
+ //===----------------------------------------------------------------------===//
239
+ // lazy.permutations(ofCount:)
240
+ //===----------------------------------------------------------------------===//
241
+
242
+ extension LazyCollectionProtocol {
243
+ /// Returns a lazy collection of the permutations of this collection of the
244
+ /// specified length.
245
+ public func permutations(
246
+ ofCount k: Int ? = nil
247
+ ) -> LazySequence < Permutations < Elements > > {
248
+ elements. permutations ( ofCount: k) . lazy
249
+ }
250
+ }
You can’t perform that action at this time.
0 commit comments