-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds the interval
operator.
#810
Conversation
In case you missed it, we have a more generalized ReactiveSwift/Sources/SignalProducer.swift Lines 1068 to 1086 in 04d406a
|
The SignalProducer("abcde")
.collect(every: .milliseconds(50), on: QueueScheduler.main, discardWhenCompleted: false)
.startWithValues {
print("\(Date()): \($0)")
} will print Whereas: SignalProducer.interval("abcde", interval: .milliseconds(50), on: QueueScheduler.main)
.startWithValues {
print("\(Date()): \($0)")
} will print each value in the sequence at 50ms intervals. One use case for this is for animating the appearance of text in the UI, as in this example: AnimatedTitle.mp4 |
The alternative to using SignalProducer(title)
.flatMap(.concat) { char in
SignalProducer(value: char)
.delay(0.05, on: QueueScheduler.main)
} |
Other than that, |
Seems like I might have misunderstood what Judging by your description, it seems SignalProducer
.timer(.milliseconds(5), on: QueueScheduler.main)
.map { date in (date, "abcde") }
// or
.map(value: "abcde") |
Wouldn't the example you provided just emit the value
FWIW: I tried creating this using |
Argh, missed the part of emitting elements in the collection one by one. Somehow thought it was repeating the string literal regularly. I think SignalProducer.zip(
SignalProducer.timer(.milliseconds(5), on: QueueScheduler.main),
SignalProducer("Hello world!") // `SignalProducer<Character, Never>
)
.scan(into: "") { $0.append($1.1) } Should work alright for small arrays/sequences.
|
The The idea of adding the Given there is prior art for this in Rx, what is the objection to adding it? When I needed this functionality I was sure there would be an operator for it, and a bit surprised that there wasn't. |
|
||
it("shouldn't overflow on a real scheduler") { | ||
let scheduler = QueueScheduler.makeForTesting() | ||
let producer = SignalProducer.interval("abc", interval: .seconds(3), on: scheduler) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe provide an astronomically large sequence with repeatElement
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 👍
@mluisbrown There is no objection, more about trying to establish the need/value other than RxSwift parity (which has never been a USP of RAS). :) |
😄 I just meant that the fact that it already exists in ReactiveX is one more factor in evaluating the usefulness. FWIW The prior art I was referring to was from ReactiveX.io |
Nice. 🤠 |
Adds the
interval
operator with functionality similar to that of the operator with the same name in ReactiveX.Allows specifying any
Sequence
, including infinite sequences such as0...
(which is the sequence used if none is provided, to mimic the ReactiveX behaviour).This can be useful, for example, to make a "typewriter" effect of characters appearing on the screen at regularly spaced intervals.
Checklist