Skip to content

Commit

Permalink
Add two convenience Property initializers.
Browse files Browse the repository at this point in the history
  • Loading branch information
andersio committed May 18, 2017
1 parent 4c52fc6 commit 101a210
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Sources/Property.swift
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,29 @@ public final class Property<Value>: PropertyProtocol {
}
}

extension Property where Value: OptionalProtocol {
/// Initializes a composed property that first takes on `initial`, then each
/// value sent on a signal created by `producer`.
///
/// - parameters:
/// - initial: Starting value for the property.
/// - values: A producer that will start immediately and send values to
/// the property.
public convenience init(initial: Value, then values: SignalProducer<Value.Wrapped, NoError>) {
self.init(initial: initial, then: values.map(Value.init(reconstructing:)))
}

/// Initialize a composed property that first takes on `initial`, then each
/// value sent on `signal`.
///
/// - parameters:
/// - initialValue: Starting value for the property.
/// - values: A signal that will send values to the property.
public convenience init(initial: Value, then values: Signal<Value.Wrapped, NoError>) {
self.init(initial: initial, then: SignalProducer(values))
}
}

/// A mutable property of type `Value` that allows observation of its changes.
///
/// Instances of this class are thread-safe.
Expand Down

0 comments on commit 101a210

Please sign in to comment.