| 63 | } |
| 64 | |
| 65 | export class MutableObservableOption<T> implements ObservableOption<T> { |
| 66 | readonly #notifier: Notifier<Option<T>> |
| 67 | |
| 68 | #option: Option<T> = Option.None |
| 69 | |
| 70 | constructor(value?: T) { |
| 71 | this.#notifier = new Notifier<Option<T>>() |
| 72 | this.wrap(value) |
| 73 | } |
| 74 | |
| 75 | wrap(value: Maybe<T>): void {this.wrapOption(Option.wrap(value))} |
| 76 | |
| 77 | wrapOption(value: Option<T>): void { |
| 78 | if (!this.#option.equals(value)) { |
| 79 | this.#option = value |
| 80 | this.#notifier.notify(this) |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | clear(procedure?: Procedure<T>): void { |
| 85 | if (this.#option.isEmpty()) {return} |
| 86 | if (isDefined(procedure)) {procedure(this.#option.unwrap())} |
| 87 | this.#option = Option.None |
| 88 | this.#notifier.notify(this) |
| 89 | } |
| 90 | |
| 91 | assert(fail?: ValueOrProvider<string>): this { |
| 92 | this.#option.assert(fail) |
| 93 | return this |
| 94 | } |
| 95 | |
| 96 | contains(value: T): boolean {return this.#option.contains(value)} |
| 97 | equals(other: Option<T>): boolean {return this.#option.equals(other)} |
| 98 | flatMap<U>(func: Func<T, Option<U>>): Option<U> {return this.#option.flatMap(func)} |
| 99 | ifSome<R>(procedure: Procedure<T>): R | undefined {return this.#option.ifSome(procedure)} |
| 100 | ifAbsent<R>(exec: Func<T, R>): R | undefined {return this.#option.ifAbsent(exec)} |
| 101 | isEmpty(): boolean {return this.#option.isEmpty()} |
| 102 | map<U>(func: Func<T, Maybe<U>>): Option<U> {return this.#option.map(func)} |
| 103 | mapOr<U>(func: Func<T, U>, or: ValueOrProvider<U>): U {return this.#option.mapOr(func, or)} |
| 104 | match<R>(matchable: Option.Matchable<T, R>): R {return this.#option.match(matchable)} |
| 105 | nonEmpty(): boolean {return this.#option.nonEmpty()} |
| 106 | unwrap(fail?: ValueOrProvider<string>): T {return this.#option.unwrap(fail)} |
| 107 | unwrapOrElse(or: ValueOrProvider<T>): T {return this.#option.unwrapOrElse(or)} |
| 108 | unwrapOrNull(): Nullable<T> {return this.#option.unwrapOrNull()} |
| 109 | unwrapOrUndefined(): T | undefined {return this.#option.unwrapOrUndefined()} |
| 110 | subscribe(observer: Observer<Option<T>>): Subscription {return this.#notifier.subscribe(() => observer(this))} |
| 111 | catchupAndSubscribe(observer: Observer<Option<T>>): Subscription { |
| 112 | observer(this) |
| 113 | return this.#notifier.subscribe(() => observer(this)) |
| 114 | } |
| 115 | terminate(): void {this.#notifier.terminate()} |
| 116 | } |
| 117 | |
| 118 | export class MappedMutableObservableValue<SOURCE, TARGET> implements MutableObservableValue<TARGET>, Terminable { |
| 119 | readonly #source: MutableObservableValue<SOURCE> |
nothing calls this directly
no outgoing calls
no test coverage detected