-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
087a90d
commit 3e4c3ad
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Observable, Operator, TeardownLogic, Subscriber } from "rxjs" | ||
|
||
/** | ||
* Represents a disjoint union of two Observables. | ||
* | ||
* An instance of `EitherObservable` is either an instance of `LeftObservable` or `RightObservable`. | ||
* Conviention is that `LeftObservable` is used for errors and `RightObservable` is used for successes. | ||
* | ||
* `EitherObservable` is right-biased, `Right` is the default case to operate on. | ||
*/ | ||
export type EitherObservable<E, A> = LeftObservable<E, A> | RightObservable<E, A> | ||
|
||
/** | ||
* Interface to ensure that LeftObservable and RightObservable have the same methods. | ||
*/ | ||
interface IEitherObservable<E, A> extends Observable<A> { | ||
readonly tag: "left" | "right"; | ||
} | ||
|
||
export class LeftObservable<E, A> implements IEitherObservable<E, A> { | ||
readonly tag: "left" = "left"; | ||
|
||
/** From RxJS docs: Internal implementation detail. */ | ||
public _isScalar = false; | ||
|
||
/** Previous Observable in the chain. */ | ||
source: Observable<any>; | ||
operator: Operator<any, A>; | ||
|
||
private readonly _subscribe?: (this: Observable<A>, subscriber: Subscriber<A>) => TeardownLogic | ||
|
||
constructor() {} | ||
} | ||
|
||
export class RightObservable<E, A> implements IEitherObservable<E, A> { | ||
readonly tag: "right" = "right"; | ||
|
||
/** From RxJS docs: Internal implementation detail. */ | ||
public _isScalar = false; | ||
} |