Skip to content

Instantly share code, notes, and snippets.

@cqfd
Created June 26, 2016 22:07
Show Gist options
  • Save cqfd/c45e517a3e787d68179d96e85a5080c8 to your computer and use it in GitHub Desktop.
Save cqfd/c45e517a3e787d68179d96e85a5080c8 to your computer and use it in GitHub Desktop.
Broken signal implementation...
class SimpleSignal<E> {
private let _v: Variable<E>
var value: E { return _v.value }
private let _disposeBag = DisposeBag()
init(initialValue: E, subsequentValues: Observable<E>) {
_v = Variable(initialValue)
subsequentValues.bindTo(self._v).addDisposableTo(_disposeBag)
}
func map<R>(selector: E -> R) -> SimpleSignal<R> {
return SimpleSignal<R>(initialValue: selector(value), subsequentValues: _v.asObservable().skip(1).map(selector))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment