如何在 ReactiveKit 中使用 ReplaySubject

How to use ReplaySubject in ReactiveKit

我在 RxSwift 中有这个:

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

如何在 ReactiveKit 中实现相同的概念?

使用目前处于测试阶段的 ReactiveKit 3(rk3 分支),您可以:

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

在 ReactiveKit 2 ReplaySubject 中泛化了事件:

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

func foo() -> Operation<Int, Error> {
  let subject = ReplaySubject<OperationEvent<Int>>(bufferSize: 1)
  return Operation(rawStream: subject.toRawStream())
}