2

I have this in RxSwift:

func foo() -> Observable<Int> {
    let subject = RxSwift.ReplaySubject<Int>.create(bufferSize: 1)
    return subject.asObservable()
}

How do I implement the same concept in ReactiveKit?

Daniel T.
  • 32,821
  • 6
  • 50
  • 72

1 Answers1

1

With ReactiveKit 3 that is currently in beta (rk3 branch) you can do:

func foo() -> Signal<Int, NoError> {
  let subject = ReplaySubject<Int, NoError>(bufferSize: 1)
  return subject.toSignal()
}

In ReactiveKit 2 ReplaySubject is generalised over events:

func foo() -> Stream<Int> {
  let subject = ReplaySubject<StreamEvent<Int>>(bufferSize: 1)
  return Stream(rawStream: subject.toRawStream())
}

or

func foo() -> Operation<Int, Error> {
  let subject = ReplaySubject<OperationEvent<Int>>(bufferSize: 1)
  return Operation(rawStream: subject.toRawStream())
}
Srđan Rašić
  • 1,597
  • 15
  • 23
  • Close! Thanks for the assist, but it looks like your second block of code should have `return Stream(rawStream: subject.toRawStream())` instead of `return subject.toStream()`. If that sounds right to you and you edit the code, I will mark it as correct. – Daniel T. Sep 02 '16 at 13:04
  • Now I just have to figure out how to bind a stream to this ReplaySubject... – Daniel T. Sep 02 '16 at 15:35