Skip to content

Commit a92032f

Browse files
authored
Merge pull request #120 from ReactiveCocoa/producer-init
Drop the label of `SignalProducer` initializers that take a sequence.
2 parents 9030845 + c000500 commit a92032f

File tree

8 files changed

+76
-70
lines changed

8 files changed

+76
-70
lines changed

ReactiveSwift.playground/Pages/SignalProducer.xcplaygroundpage/Contents.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ scopedExample("`mapError`") {
262262
Preserves only the values of the producer that pass the given predicate.
263263
*/
264264
scopedExample("`filter`") {
265-
SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
265+
SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
266266
.filter { $0 > 3 }
267267
.startWithValues { value in
268268
print(value)
@@ -275,7 +275,7 @@ Returns a producer that will yield the first `count` values from the
275275
input producer.
276276
*/
277277
scopedExample("`take(first:)`") {
278-
SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
278+
SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
279279
.take(first: 2)
280280
.startWithValues { value in
281281
print(value)
@@ -288,7 +288,7 @@ Forwards all events onto the given scheduler, instead of whichever
288288
scheduler they originally arrived upon.
289289
*/
290290
scopedExample("`observe(on:)`") {
291-
let baseProducer = SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
291+
let baseProducer = SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
292292
let completion = { print("is main thread? \(Thread.current.isMainThread)") }
293293

294294
baseProducer
@@ -391,8 +391,8 @@ least one value each. If either producer is interrupted, the returned producer
391391
will also be interrupted.
392392
*/
393393
scopedExample("`combineLatest(with:)`") {
394-
let producer1 = SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
395-
let producer2 = SignalProducer<Int, NoError>(values: [ 1, 2 ])
394+
let producer1 = SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
395+
let producer2 = SignalProducer<Int, NoError>([ 1, 2 ])
396396

397397
producer1
398398
.combineLatest(with: producer2)
@@ -407,7 +407,7 @@ Returns a producer that will skip the first `count` values, then forward
407407
everything afterward.
408408
*/
409409
scopedExample("`skip(first:)`") {
410-
SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
410+
SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
411411
.skip(first: 2)
412412
.startWithValues { value in
413413
print(value)
@@ -427,7 +427,7 @@ the Event itself and then complete. When an Interrupted event is received,
427427
the resulting producer will send the Event itself and then interrupt.
428428
*/
429429
scopedExample("`materialize`") {
430-
SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
430+
SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
431431
.materialize()
432432
.startWithValues { value in
433433
print(value)
@@ -447,8 +447,8 @@ multiple times) by `sampler`, then complete once both input producers have
447447
completed, or interrupt if either input producer is interrupted.
448448
*/
449449
scopedExample("`sample(on:)`") {
450-
let baseProducer = SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
451-
let sampledOnProducer = SignalProducer<Int, NoError>(values: [ 1, 2 ])
450+
let baseProducer = SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
451+
let sampledOnProducer = SignalProducer<Int, NoError>([ 1, 2 ])
452452
.map { _ in () }
453453

454454
baseProducer
@@ -466,7 +466,7 @@ is the current value. `initial` is supplied as the first member when `self`
466466
sends its first value.
467467
*/
468468
scopedExample("`combinePrevious`") {
469-
SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
469+
SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
470470
.combinePrevious(42)
471471
.startWithValues { value in
472472
print("\(value)")
@@ -482,7 +482,7 @@ producer returned from `scan`. That result is then passed to `combine` as the
482482
first argument when the next value is emitted, and so on.
483483
*/
484484
scopedExample("`scan`") {
485-
SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
485+
SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
486486
.scan(0, +)
487487
.startWithValues { value in
488488
print(value)
@@ -494,7 +494,7 @@ scopedExample("`scan`") {
494494
Like `scan`, but sends only the final value and then immediately completes.
495495
*/
496496
scopedExample("`reduce`") {
497-
SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
497+
SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
498498
.reduce(0, +)
499499
.startWithValues { value in
500500
print(value)
@@ -507,7 +507,7 @@ Forwards only those values from `self` which do not pass `isRepeat` with
507507
respect to the previous value. The first value is always forwarded.
508508
*/
509509
scopedExample("`skipRepeats`") {
510-
SignalProducer<Int, NoError>(values: [ 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 2, 2, 2, 4 ])
510+
SignalProducer<Int, NoError>([ 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 2, 2, 2, 4 ])
511511
.skipRepeats(==)
512512
.startWithValues { value in
513513
print(value)
@@ -521,7 +521,7 @@ at which point the returned signal behaves exactly like `self`.
521521
*/
522522
scopedExample("`skip(while:)`") {
523523
// Note that trailing closure is used for `skip(while:)`.
524-
SignalProducer<Int, NoError>(values: [ 3, 3, 3, 3, 1, 2, 3, 4 ])
524+
SignalProducer<Int, NoError>([ 3, 3, 3, 3, 1, 2, 3, 4 ])
525525
.skip { $0 > 2 }
526526
.startWithValues { value in
527527
print(value)
@@ -566,7 +566,7 @@ Waits until `self` completes and then forwards the final `count` values
566566
on the returned producer.
567567
*/
568568
scopedExample("`take(last:)`") {
569-
SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
569+
SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
570570
.take(last: 2)
571571
.startWithValues { value in
572572
print(value)
@@ -579,7 +579,7 @@ Unwraps non-`nil` values and forwards them on the returned signal, `nil`
579579
values are dropped.
580580
*/
581581
scopedExample("`skipNil`") {
582-
SignalProducer<Int?, NoError>(values: [ nil, 1, 2, nil, 3, 4, nil ])
582+
SignalProducer<Int?, NoError>([ nil, 1, 2, nil, 3, 4, nil ])
583583
.skipNil()
584584
.startWithValues { value in
585585
print(value)
@@ -593,8 +593,8 @@ Zips elements of two producers into pairs. The elements of any Nth pair
593593
are the Nth elements of the two input producers.
594594
*/
595595
scopedExample("`zip(with:)`") {
596-
let baseProducer = SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
597-
let zippedProducer = SignalProducer<Int, NoError>(values: [ 42, 43 ])
596+
let baseProducer = SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
597+
let zippedProducer = SignalProducer<Int, NoError>([ 42, 43 ])
598598

599599
baseProducer
600600
.zip(with: zippedProducer)
@@ -651,7 +651,7 @@ which case `replacement` will not be started, and none of its events will be
651651
be forwarded. All values sent from `producer` are ignored.
652652
*/
653653
scopedExample("`then`") {
654-
let baseProducer = SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
654+
let baseProducer = SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
655655
let thenProducer = SignalProducer<Int, NoError>(value: 42)
656656

657657
baseProducer
@@ -686,7 +686,7 @@ a layer of caching in front of another `SignalProducer`.
686686
This operator has the same semantics as `SignalProducer.buffer`.
687687
*/
688688
scopedExample("`replayLazily(upTo:)`") {
689-
let baseProducer = SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4, 42 ])
689+
let baseProducer = SignalProducer<Int, NoError>([ 1, 2, 3, 4, 42 ])
690690
.replayLazily(upTo: 2)
691691

692692
baseProducer.startWithValues { value in
@@ -712,7 +712,7 @@ If `self` or any of the created producers fail, the returned producer
712712
will forward that failure immediately.
713713
*/
714714
scopedExample("`flatMap(.latest)`") {
715-
SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
715+
SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
716716
.flatMap(.latest) { SignalProducer(value: $0 + 3) }
717717
.startWithValues { value in
718718
print(value)
@@ -743,8 +743,8 @@ sampled (possibly multiple times) by `sampler`, then complete once both
743743
input producers have completed, or interrupt if either input producer is interrupted.
744744
*/
745745
scopedExample("`sample(with:)`") {
746-
let producer = SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4 ])
747-
let sampler = SignalProducer<String, NoError>(values: [ "a", "b" ])
746+
let producer = SignalProducer<Int, NoError>([ 1, 2, 3, 4 ])
747+
let sampler = SignalProducer<String, NoError>([ "a", "b" ])
748748

749749
let result = producer.sample(with: sampler)
750750

@@ -759,7 +759,7 @@ Logs all events that the receiver sends.
759759
By default, it will print to the standard output.
760760
*/
761761
scopedExample("`log events`") {
762-
let baseProducer = SignalProducer<Int, NoError>(values: [ 1, 2, 3, 4, 42 ])
762+
let baseProducer = SignalProducer<Int, NoError>([ 1, 2, 3, 4, 42 ])
763763

764764
baseProducer
765765
.logEvents(identifier: "Playground is fun!")

Sources/Deprecations+Removals.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ extension SignalProducerProtocol where Error == NoError {
297297
extension SignalProducer {
298298
@available(*, unavailable, message:"Use properties instead. `buffer(_:)` is removed in RAC 5.0.")
299299
public static func buffer(_ capacity: Int) -> (SignalProducer, Signal<Value, Error>.Observer) { fatalError() }
300+
301+
@available(*, unavailable, renamed:"init(_:)")
302+
public init<S: SignalProtocol>(signal: S) where S.Value == Value, S.Error == Error { fatalError() }
303+
304+
@available(*, unavailable, renamed:"init(_:)")
305+
public init<S: Sequence>(values: S) where S.Iterator.Element == Value { fatalError() }
300306
}
301307

302308
extension PropertyProtocol {

Sources/Flatten.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ extension SignalProtocol where Value: Sequence, Error == NoError {
249249
/// Flattens the `sequence` value sent by `signal` according to
250250
/// the semantics of the given strategy.
251251
public func flatten(_ strategy: FlattenStrategy) -> Signal<Value.Iterator.Element, Error> {
252-
return self.flatMap(strategy) { .init(values: $0) }
252+
return self.flatMap(strategy) { .init($0) }
253253
}
254254
}
255255

@@ -316,7 +316,7 @@ extension SignalProducerProtocol where Value: Sequence, Error == NoError {
316316
/// Flattens the `sequence` value sent by `producer` according to
317317
/// the semantics of the given strategy.
318318
public func flatten(_ strategy: FlattenStrategy) -> SignalProducer<Value.Iterator.Element, Error> {
319-
return self.flatMap(strategy) { .init(values: $0) }
319+
return self.flatMap(strategy) { .init($0) }
320320
}
321321
}
322322

@@ -440,7 +440,7 @@ extension SignalProducerProtocol where Value: SignalProducerProtocol, Error == V
440440
extension SignalProducerProtocol {
441441
/// `concat`s `next` onto `self`.
442442
public func concat(_ next: SignalProducer<Value, Error>) -> SignalProducer<Value, Error> {
443-
return SignalProducer<SignalProducer<Value, Error>, Error>(values: [ self.producer, next ]).flatten(.concat)
443+
return SignalProducer<SignalProducer<Value, Error>, Error>([ self.producer, next ]).flatten(.concat)
444444
}
445445

446446
/// `concat`s `value` onto `self`.
@@ -578,7 +578,7 @@ extension SignalProtocol {
578578
public static func merge<Seq: Sequence, S: SignalProtocol>(_ signals: Seq) -> Signal<Value, Error>
579579
where S.Value == Value, S.Error == Error, Seq.Iterator.Element == S
580580
{
581-
return SignalProducer<S, Error>(values: signals)
581+
return SignalProducer<S, Error>(signals)
582582
.flatten(.merge)
583583
.startAndRetrieveSignal()
584584
}
@@ -599,7 +599,7 @@ extension SignalProducerProtocol {
599599
public static func merge<Seq: Sequence, S: SignalProducerProtocol>(_ producers: Seq) -> SignalProducer<Value, Error>
600600
where S.Value == Value, S.Error == Error, Seq.Iterator.Element == S
601601
{
602-
return SignalProducer(values: producers).flatten(.merge)
602+
return SignalProducer(producers).flatten(.merge)
603603
}
604604

605605
/// Merges the given producers into a single `SignalProducer` that will emit

Sources/Property.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,20 +456,20 @@ public final class Property<Value>: PropertyProtocol {
456456
///
457457
/// - parameters:
458458
/// - initial: Starting value for the property.
459-
/// - producer: A producer that will start immediately and send values to
460-
/// the property.
461-
public convenience init(initial: Value, then producer: SignalProducer<Value, NoError>) {
462-
self.init(unsafeProducer: producer.prefix(value: initial))
459+
/// - values: A producer that will start immediately and send values to
460+
/// the property.
461+
public convenience init(initial: Value, then values: SignalProducer<Value, NoError>) {
462+
self.init(unsafeProducer: values.prefix(value: initial))
463463
}
464464

465465
/// Initialize a composed property that first takes on `initial`, then each
466466
/// value sent on `signal`.
467467
///
468468
/// - parameters:
469469
/// - initialValue: Starting value for the property.
470-
/// - signal: A signal that will send values to the property.
471-
public convenience init(initial: Value, then signal: Signal<Value, NoError>) {
472-
self.init(unsafeProducer: SignalProducer(signal: signal).prefix(value: initial))
470+
/// - values: A signal that will send values to the property.
471+
public convenience init(initial: Value, then values: Signal<Value, NoError>) {
472+
self.init(unsafeProducer: SignalProducer(values).prefix(value: initial))
473473
}
474474

475475
/// Initialize a composed property by applying the unary `SignalProducer`

Sources/SignalProducer.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public struct SignalProducer<Value, Error: Swift.Error> {
2929
///
3030
/// - parameters:
3131
/// - signal: A signal to observe after starting the producer.
32-
public init<S: SignalProtocol>(signal: S) where S.Value == Value, S.Error == Error {
32+
public init<S: SignalProtocol>(_ signal: S) where S.Value == Value, S.Error == Error {
3333
self.init { observer, disposable in
3434
disposable += signal.observe(observer)
3535
}
@@ -100,7 +100,7 @@ public struct SignalProducer<Value, Error: Swift.Error> {
100100
/// - parameters:
101101
/// - values: A sequence of values that a `Signal` will send as separate
102102
/// `value` events and then complete.
103-
public init<S: Sequence>(values: S) where S.Iterator.Element == Value {
103+
public init<S: Sequence>(_ values: S) where S.Iterator.Element == Value {
104104
self.init { observer, disposable in
105105
for value in values {
106106
observer.send(value: value)
@@ -122,7 +122,7 @@ public struct SignalProducer<Value, Error: Swift.Error> {
122122
/// - second: Second value for the `Signal` to send.
123123
/// - tail: Rest of the values to be sent by the `Signal`.
124124
public init(values first: Value, _ second: Value, _ tail: Value...) {
125-
self.init(values: [ first, second ] + tail)
125+
self.init([ first, second ] + tail)
126126
}
127127

128128
/// A producer for a Signal that will immediately complete without sending
@@ -448,7 +448,7 @@ extension SignalProducerProtocol {
448448
/// `SignalProducer`.
449449
public func lift<U, F, V, G>(_ transform: @escaping (Signal<Value, Error>) -> (Signal<U, F>) -> Signal<V, G>) -> (Signal<U, F>) -> SignalProducer<V, G> {
450450
return { otherSignal in
451-
return self.liftRight(transform)(SignalProducer(signal: otherSignal))
451+
return self.liftRight(transform)(SignalProducer(otherSignal))
452452
}
453453
}
454454

Tests/ReactiveSwiftTests/PropertySpec.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class PropertySpec: QuickSpec {
578578

579579
let (signal, observer) = Signal<Int, NoError>.pipe()
580580
var property: Property<Int>? = Property(initial: 1,
581-
then: SignalProducer(signal: signal))
581+
then: SignalProducer(signal))
582582
let propertySignal = property!.signal
583583

584584
propertySignal.observeCompleted { signalCompleted = true }
@@ -1539,7 +1539,7 @@ class PropertySpec: QuickSpec {
15391539
describe("from a SignalProducer") {
15401540
it("should start a signal and update the property with its values") {
15411541
let signalValues = [initialPropertyValue, subsequentPropertyValue]
1542-
let signalProducer = SignalProducer<String, NoError>(values: signalValues)
1542+
let signalProducer = SignalProducer<String, NoError>(signalValues)
15431543

15441544
let mutableProperty = MutableProperty(initialPropertyValue)
15451545

@@ -1562,7 +1562,7 @@ class PropertySpec: QuickSpec {
15621562

15631563
it("should tear down the binding when the property deallocates") {
15641564
let (signal, _) = Signal<String, NoError>.pipe()
1565-
let signalProducer = SignalProducer(signal: signal)
1565+
let signalProducer = SignalProducer(signal)
15661566

15671567
var mutableProperty: MutableProperty<String>? = MutableProperty(initialPropertyValue)
15681568

Tests/ReactiveSwiftTests/SignalProducerLiftingSpec.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ class SignalProducerLiftingSpec: QuickSpec {
999999
}
10001000

10011001
it("should emit an initial value if the sampler is a synchronous SignalProducer") {
1002-
let producer = SignalProducer<Int, NoError>(values: [1])
1002+
let producer = SignalProducer<Int, NoError>([1])
10031003
let sampler = SignalProducer<String, NoError>(value: "a")
10041004

10051005
let result = producer.sample(with: sampler)
@@ -1064,7 +1064,7 @@ class SignalProducerLiftingSpec: QuickSpec {
10641064
}
10651065

10661066
it("should emit an initial value if the sampler is a synchronous SignalProducer") {
1067-
let producer = SignalProducer<Int, NoError>(values: [1])
1067+
let producer = SignalProducer<Int, NoError>([1])
10681068
let sampler = SignalProducer<(), NoError>(value: ())
10691069

10701070
let result = producer.sample(on: sampler)

0 commit comments

Comments
 (0)