{"id":24108310,"url":"https://github.com/reactgular/observables","last_synced_at":"2025-08-18T21:07:50.493Z","repository":{"id":143783828,"uuid":"194102726","full_name":"reactgular/observables","owner":"reactgular","description":"TypeScript library that contains handy rxjs 6 operators.","archived":false,"fork":false,"pushed_at":"2020-09-17T16:46:25.000Z","size":278,"stargazers_count":8,"open_issues_count":12,"forks_count":2,"subscribers_count":0,"default_branch":"develop","last_synced_at":"2025-06-13T16:36:59.925Z","etag":null,"topics":["rxjs","rxjs-library","rxjs-observables","rxjs-operators","rxjs6"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reactgular.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-06-27T13:41:24.000Z","updated_at":"2022-08-23T02:09:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"58deb71f-f52d-4cc1-a97e-6e4b7221d302","html_url":"https://github.com/reactgular/observables","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/reactgular/observables","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactgular%2Fobservables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactgular%2Fobservables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactgular%2Fobservables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactgular%2Fobservables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reactgular","download_url":"https://codeload.github.com/reactgular/observables/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactgular%2Fobservables/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261226176,"owners_count":23127275,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rxjs","rxjs-library","rxjs-observables","rxjs-operators","rxjs6"],"created_at":"2025-01-10T23:35:52.802Z","updated_at":"2025-08-18T21:07:50.479Z","avatar_url":"https://github.com/reactgular.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/reactgular/observables.svg?branch=master)](https://travis-ci.org/reactgular/observables)\n[![Coverage Status](https://coveralls.io/repos/github/reactgular/observables/badge.svg?branch=master)](https://coveralls.io/github/reactgular/observables?branch=master)\n[![npm version](https://badge.fury.io/js/%40reactgular%2Fobservables.svg)](https://badge.fury.io/js/%40reactgular%2Fobservables)\n\n## What is Observables?\n\nObservables is a small Rxjs 6 library that contains handy operators and utilities.\n\n## Why use this rxjs library?\n\nThis library contains operators and utilities that solve some very common problems that I face with Rxjs. Here is\na quick list of features that I use most often in projects.\n\n- [ifOp()](#ifop) apply operators based upon conditions.\n- [windowResize()](#windowresize) creates a debounced observable of window size changes.\n- [withSwitchMap()](#withswitchmap) and [withMergeMap()](#withmergemap) but emits the outer and inner values.\n- [enabledWhen()](#enabledwhen) and [disabledWhen()](#disabledwhen) toggle the flow of values.\n- [loadFirst()](#loadfirst) emits a state object for HTTP requests.\n- [switchChain()](#switchchain) links together multiple [switchMap()](https://rxjs.dev/api/operators/switchMap) operators.\n\n## Installation\n\nTo get started, install the package from npm.\n\n```bash\nnpm install @reactgular/observables\n```\n\nThis package requires the Rxjs 6 as a peer dependency.\n\n```bash\nnpm install rxjs\n```\n\n## Usage\n\nOperators and utilities are imported from the package path `@reactgular/observables`.\n\nFor example;\n\n```typescript\nimport {Observable} from 'rxjs';\nimport {windowResize, distinctStringify} from '@reactgular/observables';\n\nfunction conditionalResize(cond$: Observable\u003cboolean\u003e): Observable\u003c{}\u003e {\n    return windowResize(250).pipe(\n      enabledWhen(cond$)\n    );\n}\n```\n\n# Operators\n\nHere is a list of observable operators that you can use from this library.\n\nOperators | Operators | Operators | Operators | Operators | Operators\n----------|-----------|-----------|-----------|-----------|-----------\n[after](#after) | [before](#before) | [beforeError](#beforeerror) | [counter](#counter) | [disabledWhen](#disabledwhen) | [distinctArray](#distinctarray)\n[distinctDeepEqual](#distinctdeepequal) | [distinctStringify](#distinctstringify) | [enabledWhen](#enabledwhen) | [falsy](#falsy) | [historyBuffer](#historybuffer) | [ifOp](#ifop)\n[loadFirst](#loadfirst) | [mapFirst](#mapfirst) | [mapLast](#maplast) | [negate](#negate) | [pluckDistinct](#pluckdistinct) | [scanLatestFrom](#scanlatestfrom)\n[truthy](#truthy) | [withMergeMap](#withmergemap) | [withSwitchMap](#withswitchmap) | [](#) | [](#) | [](#)\n\n# Utilities\n\nHere is a list of utility functions that you can use from this library.\n\nOperators | Operators | Operators | Operators | Operators | Operators\n----------|-----------|-----------|-----------|-----------|-----------\n[combineEarliest](#combineearliest) | [mergeChain](#mergechain) | [mergeDelayError](#mergedelayerror) | [mergeTrim](#mergetrim) | [roundRobin](#roundrobin) | [switchChain](#switchchain)\n[toObservable](#toobservable) | [windowResize](#windowresize) | [](#) | [](#) | [](#) | [](#)\n\n\n## Operators List\n\n### after\n\nEmits the value that came after the value that passed the provided condition.\n\nThis operator has the following limitations:\n\n- This operator will never emit if the observable only emits one or fewer values.\n- This operator will never emit the first value.\n- If no values pass the provided condition, then nothing is emitted.\n\n```typescript\nafter\u003cT\u003e(cond: (current: T, next: T) =\u003e boolean): MonoTypeOperatorFunction\u003cT\u003e\n```\n\nExample:\n\n```typescript\nof('starting', 'started', 'error', 'restarting').pipe(\n    after(v =\u003e v === 'error')\n).subscribe(v =\u003e console.log(v)); // prints \"restarting\"\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/after.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/after.spec.ts)] [[up](#operators)]\n\n----\n### before\n\nEmits the value that came before the value that passed the provided condition.\n\nThis operator has the following limitations:\n\n- This operator will never emit if the observable only emits one or fewer values.\n- This operator will never emit the last value.\n- If no values pass the provided condition, then nothing is emitted.\n\n```typescript\nbefore\u003cT\u003e(cond: (current: T, prev: T) =\u003e boolean): MonoTypeOperatorFunction\u003cT\u003e\n```\n\nExample:\n\n```typescript\nof('starting', 'started', 'error', 'restarting').pipe(\n    before(v =\u003e v === 'error')\n).subscribe(v =\u003e console.log(v)); // prints \"started\"\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/before.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/before.spec.ts)] [[up](#operators)]\n\n----\n### beforeError\n\nEmits an array of values that came before an error and silences the error. You can specify how many values to emit upon an error (the default is `1`).\nThe emitted array contains the most recent value first followed by older values.\n\n\u003e This is a good operator for debugging to see what values preceded an error. \n\nExample:\n\n```typescript\nof('starting','started','restarting').pipe(\n    map(n =\u003e {\n        if(n === 'restarting') { throw new Error() }\n        return n;\n    }),\n    beforeError()\n}).subscribe(v =\u003e console.log(v)); // prints [\"started\"]\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/beforeError.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/beforeError.spec.ts)] [[up](#operators)]\n\n----\n### counter\n\nIncrements a counter for each emitted value.\n\n```typescript\ncounter\u003cT\u003e(): OperatorFunction\u003cT, [number, T]\u003e\n```\n\nExample:\n\n```typescript\nof('a', 'b', 'c', 'd').pipe(\n    counter()\n).subscribe(v =\u003e console.log(v));\n// [1, 'a']\n// [2, 'b']\n// [3, 'c']\n// [4, 'd']    \n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/counter.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/counter.spec.ts)] [[up](#operators)]\n\n----\n### disabledWhen\n\nThe inner observable can emit a *truthy* value to stop the emitting of values from the\nouter observable, and emit a *falsy* to resume emitting values.\n\n\u003e Does not emit any values until the inner observable emits a *falsy* value.\n\n```typescript\ndisabledWhen\u003cT\u003e(disabled$: Observable\u003cboolean\u003e): MonoTypeOperatorFunction\u003cT\u003e\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/disabled-when.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/disabled-when.spec.ts)] [[up](#operators)]\n\n----\n### distinctArray\n\nOnly emits when an array contains different values than the last and ignores the order of those values. The array must contain sortable\nvalues otherwise the results are unpredictable.\n\n\u003e This operator sorts each array value before comparison.\n\n```typescript\ndistinctArray\u003cT\u003e(): MonoTypeOperatorFunction\u003cT[]\u003e\n```\n\nExample:\n\n```typescript\nof([1,2,3], [3,2,1], [1, 3, 2], [4, 5, 6], [1, 2, 3]).pipe(\n    distinctArray()\n).subscribe(v =\u003e console.log(v));\n// prints\n// [1,2,3]\n// [4,5,6]\n// [1,2,3]\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/distinct-array.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/distinct-array.spec.ts)] [[up](#operators)]\n\n----\n### distinctDeepEqual\n\nOnly emits when the current value is deeply different than the last. Two values that have different references, but contain the\nsame properties will be compared to be the same. This is the same for arrays, nested objects, dates and regular expressions.\n \n```typescript\ndistinctDeepEqual\u003cT\u003e(): MonoTypeOperatorFunction\u003cT\u003e\n```\n\nExample:\n\n```typescript\nof([1,2],[2,1],{a:1, b:1},{b:1, a:1}).pipe(\n    distinctDeepEqual()\n).subscribe(v =\u003e console.log(v));\n// prints\n// [1,2]\n// {a:1, b:1}\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/distinct-deep-equal.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/distinct-deep-equal.spec.ts)] [[up](#operators)]\n\n----\n### distinctStringify\n\nEmits all items from the source Observable that are distinct by comparison using `JSON.stringify()` on each value.\n\n\u003e Arrays with same values in different orders will be seen as different, and the same for objects with properties in different order.\n\n```typescript\ndistinctStringify\u003cT\u003e(): MonoTypeOperatorFunction\u003cT\u003e\n```\n\nExample:\n\n```typescript\nof([1,2,3], [1,2,3], [3,2,1], {a: 1}, {a: 1}, {a: 1, b: 1}, {b: 1, a: 1}, \"one\", \"one\", \"two\")\n    .pipe(distinctStringify())\n    .subscribe(v =\u003e console.log(v));\n\n// [1,2,3]\n// [3,2,1]\n// {a: 1}\n// {a: 1, b: 1}\n// {b: 1, a: 1}\n// \"one\"\n// \"two\"\n``` \n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/distinct-stringify.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/distinct-stringify.spec.ts)] [[up](#operators)]\n\n----\n### enabledWhen\n\nThe inner observable can emit a *falsy* value to stop the emitting of values from the\nouter observable, and emit a *truthy* to resume emitting values.\n\n\u003e Does not emit any values until the inner observable emits a *truthy* value.\n\n```typescript\nenabledWhen\u003cT\u003e(enabled: Observable\u003cboolean\u003e): MonoTypeOperatorFunction\u003cT\u003e\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/enabled-when.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/enabled-when.spec.ts)] [[up](#operators)]\n\n----\n### falsy\n\nEmits only *falsy* values. Performs a `filter(v =\u003e !v)` operator internally.\n\n```typescript\nfalsy\u003cT\u003e(): MonoTypeOperatorFunction\u003cT\u003e\n```\n\nExample:\n\n```typescript\nof(0, \"Hello\", false, [1,2], \"\")\n    .pipe(falsy(), toArray())\n    .subscribe(v =\u003e console.log(v)); // prints [0, false, \"\"]\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/falsy.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/falsy.spec.ts)] [[up](#operators)]\n\n----\n### historyBuffer\n\nEmits an array that starts with the current value followed by previous values. Pass a count number to limit the\nlength of the array, otherwise the array will continue to grow in length until the observable completes. \n\n```typescript\nhistoryBuffer\u003cT\u003e(count?: number): OperatorFunction\u003cT, T[]\u003e\n```\n\nExample:\n\n```typescript\nof(1,2,3,4,5).pipe(\n   bufferHistory(3)\n).subscribe(v =\u003e console.log(v));\n// [1]\n// [2,1]\n// [3,2,1]\n// [4,3,2]\n// [5,4,3]\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/historyBuffer.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/historyBuffer.spec.ts)] [[up](#operators)]\n\n----\n### ifOp\n\nApply an operator based on a condition. This operator only adds another operator when the\ncondition is *true*. When the condition is *false* the source observable is not modified.\n\n```typescript\nifOp\u003cT, R\u003e(cond: boolean, operator: OperatorFunction\u003cT, R\u003e): OperatorFunction\u003cT, T | R\u003e\n```\n\nExamples:\n\nCreates an observable of Window resize events with optional debouncing.\n\n```typescript\nwindowResize(debounce?: number) {\n   return fromEvent(window, 'resize').pipe(\n      ifOp(Boolean(debounce), debounceTime(debounce))\n   );\n}\n```\n\nIf you are looking to apply two different operators based upon a conditional *if/else*, then you can use\na simple `?:` condition in the `pipe()` chain.\n\n```typescript\nfunction switchOrMerge(cond: boolean): Observable\u003cnumber\u003e {\n    const projector = (value) =\u003e of(value).pipe(startWith(99));\n    return of(1,2,3).pipe(\n       cond ? switchMap(projector) : mergeMap(projector)\n    );\n}\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/if-op.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/if-op.spec.ts)] [[up](#operators)]\n\n----\n### loadFirst\n\nEmits objects that describe the loading of data from a remote resource (like making a HTTP request). The objects\ncontain the *status* property which can be either `\"start\"`, `\"value\"` or `\"error\"`, and a *value* property which\nholds the first data emitted by the outer observable.\n \n\u003e This operator only reads the *first* value from the outer observable, and then completes.\n\nThere is always a *start* object emitted first followed by either a *value* or *error* object. The *error* object\ncan be a thrown error or the result of the outer observable *completing* without any results.\n\n```typescript\nexport interface LoadFirst\u003cT\u003e {\n    status: string;\n    value: T | undefined;\n}\n\nloadFirst\u003cT, S, E\u003e(start?: S, empty?: E): OperatorFunction\u003cT, LoadFirst\u003cT | S | E\u003e\u003e\n```\n\nExample:\n\n```typescript\nof(\"Hello World\").pipe(\n    loadFirst()\n).subscribe(v =\u003e console.log(v));\n// prints \n// {state: \"start\", value: undefined}\n// {state: \"value\", value: \"Hello World\"}\n```\n\nYou can use this operator to make loading indicators for Angular components.\n\nExample:\n\n```typescript\nimport {loadFirst, LoadFirst} from '@reactgular/observable/operators';\n\n@Component({\n    selector: 'example',\n    template: `\n        \u003cng-container *ngIf=\"load$ | async as load\" [ngSwitch]=\"load.status\"\u003e\n            \u003cdiv *ngSwitchCase='\"start\"'\u003e\n                Please wait while loading...\n            \u003c/div\u003e\n            \u003cdiv *ngSwitchCase='\"value\"'\u003e\n                {{load.value}}\n            \u003c/div\u003e\n            \u003cdiv *ngSwitchCase='\"error\"'\u003e\n                There was an error loading data...\n            \u003c/div\u003e\n        \u003c/ng-container\u003e`\n})\nexport class ExampleComponent implements OnInit {\n    public load$: Observable\u003cLoadFirst\u003cany\u003e\u003e;\n   \n    public constructor(private http: HttpClient) { }\n   \n    public ngOnInit() {\n        this.data$ = this.http\n            .get('https://example.com/api')\n            .pipe(loadFirst());    \n    }\n}\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/load-first.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/load-first.spec.ts)] [[up](#operators)]\n\n----\n### mapFirst\n\nApplies a given `project` function to the first value emitted by the source Observables, and emits the resulting value. Only the first\nvalue is projected and subsequent values are emitted without projection.\n\n\u003e This operator is an alias for doing `map((value, indx) =\u003e indx === 0 ? project(value) : value)` \n\nExample:\n\n```typescript\nof(1,2,3,4).pipe(\n    mapFirst(v =\u003e v * 100)\n).subscribe(v =\u003e console.log(v)); \n// 100\n// 2\n// 3\n// 4\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/map-first.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/map-first.spec.ts)] [[up](#operators)]\n\n----\n### mapLast\n\nApplies a given `project` function to the last value emitted by the source Observables, and emits the resulting value. Only the last\nvalue is projected and previous values are emitted without projection. This operator uses [pairwise()](https://rxjs.dev/api/operators/pairwise) \ninternally and emits each value only when a next value is emitted or the source observable completes.\n\n\u003e If you use both `mapFirst()` and `mapLast()` on an observable that emits only a single value and completes, then both operators will project on the same value.\n\nThis operator has the following limitations:\n\n- Each emitted value is the previous value from the source observable, and the last value is flushed out when the source completes.\n- Projects the last value even if the observable emits only a single value and completes.\n\n```typescript\nmapLast\u003cT, R\u003e(project: (value: T) =\u003e R): OperatorFunction\u003cT, T | R\u003e\n```\n\nExample:\n\n```typescript\nof(1,2,3).pipe(\n    mapLast(v =\u003e v + 1000)\n).subscribe(v =\u003e console.log(v));\n// 1\n// 2\n// 1003\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/map-last.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/map-last.spec.ts)] [[up](#operators)]\n\n----\n### negate\n\nMaps *truthy* values to `false`, and *falsy* values to `true`. Performs a `map(v =\u003e !v)` internally.\n\n```typescript\nnegate\u003cT\u003e(): OperatorFunction\u003cT, boolean\u003e\n```\n\nExample:\n\n```typescript\nof(0, \"Hello\", false, [1,2,3], \"\").pipe(\n    negate(),\n    toArray()\n).subscribe(v =\u003e console.log(v));\n// prints [true, false, true, false, true]\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/negate.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/negate.spec.ts)] [[up](#operators)]\n\n----\n### pluckDistinct\n\nMaps each source value (an object) to its specified nested property,\nand only emits distinct changes. It is the same as applying a [pluck()](https://rxjs.dev/api/operators/pluck)\nfollowed by a [distinctUntilChanged()](https://rxjs.dev/api/operators/distinctUntilChanged).\n\n```typescript\npluckDistinct\u003cT, R\u003e(...properties: string[]): OperatorFunction\u003cT, R\u003e\n```\n\nExample:\n\n```typescript\nfrom([\n    {name: 'John Smith'},\n    {name: 'John Smith'},\n    {name: 'Jane Doe'},\n    {name: 'Jane Doe'}\n]).pipe(\n    pluckDistinct('name'),\n    toArray()\n).subscribe(v =\u003e console.log(v)); // prints ['John Smith', 'Jane Doe']\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/pluck-distinct.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/pluck-distinct.spec.ts)] [[up](#operators)]\n\n----\n### scanLatestFrom\n\nApplies an accumulator function over the source Observable, and returns each intermediate result. The seed value is\nthe latest value from the second observable. If the source observable emits multiple values before the second observable emits a value, then the latest\nfrom both observables will be used instead. Accumulated values are discarded when the second observable emits a seed value. \n\n\u003e Accumulated values are discarded when the second observable emits a seed value, and a new value is calculate using the accumulator function.\n\nAccumulator function parameters:\n\n- `acc` is the accumulated value and is either the *latest* value from the second observable or the previous value from the accumulator.\n- `value` is the value from the source observable.\n- `index` is the offset number from the source observable.\n- `reset` is *true* when the `acc` parameter has been reset by the second observable emitting a value.\n\n```typescript\nscanLatestFrom\u003cT, A, R\u003e(accumulator: (acc: A | R, value: T, index: number, reset: boolean) =\u003e R, latest: Observable\u003cA\u003e): OperatorFunction\u003cT, R\u003e\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/scan-latest-from.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/scan-latest-from.spec.ts)] [[up](#operators)]\n\n----\n### truthy\n\nEmits only truthy values. This operator is an alias for `filter(v =\u003e Boolean(v))`, but most people write\n`filter(Boolean)` because it's shorter. The problem with using `filter(Boolean)` is that the observable\ntype can change to `Boolean` by TypeScript. So using `truthy()` is a shorter alias for the longer form that persists the\ngeneric type. \n\n```typescript\ntruthy\u003cT\u003e(): MonoTypeOperatorFunction\u003cT\u003e\n```\n\nExample:\n\n```typescript\nof(0, false, [1,2,3], \"Hello\", \"\", {}).pipe(\n    truthy(),\n    toArray()\n).subscribe(v =\u003e console.log(v));\n// prints [[1,2,3], \"Hello\", {}]\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/truthy.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/truthy.spec.ts)] [[up](#operators)]\n\n----\n### withMergeMap\n\nApplies a [mergeMap](https://rxjs.dev/api/operators/mergeMap) to the outer observable, and maps the inner observable to an array that contains\nthe value of both the outer and inner observables as `Observable\u003c[outer, inner]\u003e`.\n\n```typescript\nwithMergeMap\u003cT, R\u003e(inner: (x: T) =\u003e Observable\u003cR\u003e): OperatorFunction\u003cT, [T, R]\u003e\n```\n\nExample:\n\n```typescript\nof('A', 'B', 'C').pipe(\n    withMergeMap(() =\u003e of('1'))\n).subscribe(v =\u003e console.log(v));\n// ['A', '1']\n// ['B', '1']\n// ['C', '1']\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/with-merge-map.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/with-merge-map.spec.ts)] [[up](#operators)]\n\n----\n### withSwitchMap\n\nApplies a [switchMap](https://rxjs.dev/api/operators/switchMap) to the outer observable, and maps the inner observable to an array that contains\nthe value of both the outer and inner observables as `Observable\u003c[outer, inner]\u003e`.\n\n```typescript\nwithSwitchMap\u003cT, R\u003e(inner: (x: T) =\u003e Observable\u003cR\u003e): OperatorFunction\u003cT, [T, R]\u003e\n```\n\nExample:\n\n```typescript\nof('A', 'B', 'C').pipe(\n    withSwitchMap(() =\u003e of('1'))\n).subscribe(v =\u003e console.log(v));\n// ['A', '1']\n// ['B', '1']\n// ['C', '1']\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/operators/with-switch-map.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/operators/with-switch-map.spec.ts)] [[up](#operators)]\n\n----\n## Utilities List\n\n### combineEarliest\n\nUnlike [combineLatest()](https://rxjs.dev/api/index/function/combineLatest) which does not emit a value until\nall observables emits at least one value. The `combineEarliest()` emits immediately upon the\nfirst observable that emits a value substituting a value (defaults to `undefined`) for any awaiting values from the\nother observables.\n\n```typescript\ncombineEarliest\u003cO extends Observable\u003cany\u003e, S, R\u003e(observables: O[], substitute?: S): Observable\u003cR\u003e\n```\n\nExample:\n\n```typescript\ncombineEarliest([\n    interval(1000),\n    of('A').pipe(delay(1000)),\n    of('B').pipe(delay(2000))\n]).pipe(take(3)).subscribe(v =\u003e console.log(v));\n\n// [0, undefined, undefined]\n// [1, 'A', undefined]\n// [2, 'A', 'B']\n``` \n\n[[source](https://github.com/reactgular/observables/blob/master/src/utils/combine-earliest.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/utils/combine-earliest.spec.ts)] [[up](#utilities)]\n\n----\n### mergeChain\n\nWhen the source observable emits a value it is passed to the next *switchTo* function which returns another observable, and the\nvalue from that observable is passed onto the next *switchTo* function. It creates a new observable that emits an array of\nall values emitted from chained observables. \n\n\u003e Uses [mergeMap()](https://rxjs.dev/api/operators/mergeMap) internally to chain the functions together.\n\n```typescript\nmergeChain\u003cT, R\u003e(source: Observable\u003cT\u003e, ...mergeTo: Array\u003c(...values: any[]) =\u003e Observable\u003cany\u003e\u003e): Observable\u003cR\u003e\n```\n\nExample:\n\n```typescript\nmergeChain(\n    store.select('company'),\n    (company) =\u003e store.selectPriceChanges(company.id),\n    (price, company) =\u003e store.selectPriceUpdates(price.id)\n).subscribe(([changes, price, company]) =\u003e console.log(changes, price, company));\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/utils/merge-chain.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/utils/merge-chain.spec.ts)] [[up](#utilities)]\n\n----\n### mergeDelayError\n\nCreates an output observable which concurrently emits all values from every\ngiven input observable, but delays any thrown errors until all observables have \ncompleted, and throws the first error.\n\n\u003e All observables must complete before any awaiting error are thrown.\n\n```typescript\nmergeDelayError\u003cT\u003e(...observables: Observable\u003cT\u003e[]): Observable\u003cT\u003e\n```\n\nExample:\n\n```typescript\nmergeDelayError(\n    of(1,2,3),\n    throwError('ERROR')\n).subscribe(\n    v =\u003e console.log(v),\n    err =\u003e console.error(err)\n);\n// prints\n// 1\n// 2\n// 3\n// ERROR\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/utils/merge-delay-error.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/utils/merge-delay-error.spec.ts)] [[up](#utilities)]\n\n----\n### mergeTrim\n\nCreates an output observable which concurrently emits all values from every \ngiven input observable until any observable completes.\n\n```typescript\nmergeTrim\u003cT\u003e(...observables: Observable\u003cT\u003e[]): Observable\u003cT\u003e\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/utils/merge-trim.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/utils/merge-trim.spec.ts)] [[up](#utilities)]\n\n----\n### roundRobin\n\nCreates an output observable which emits values from each observable in a round robin sequence. Where the first observable must emit\na value, before the next observable emits a value and starts over after all observables have emitted a value.\n\n```typescript\nfunction roundRobin\u003cT\u003e(...observables: Observable\u003cT\u003e[]): Observable\u003cT\u003e\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/utils/round-robin.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/utils/round-robin.spec.ts)] [[up](#utilities)]\n\n----\n### switchChain\n\nWhen the source observable emits a value it is passed to the next *switchTo* function which returns another observable, and the\nvalue from that observable is passed onto the next *switchTo* function. It creates a new observable that emits an array of\nall values emitted from chained observables. \n\n\u003e Uses [switchMap()](https://rxjs.dev/api/operators/switchMap) internally to chain the functions together.\n\n```typescript\nswitchChain\u003cT, R\u003e(source: Observable\u003cT\u003e, ...switchTo: Array\u003c(...values: any[]) =\u003e Observable\u003cany\u003e\u003e): Observable\u003cR\u003e\n```\n\nExample:\n\n```typescript\nswitchChain(\n    http.get('/user'),\n    (user) =\u003e http.get(`/projects/${user.projectId}`),\n    (project, user) =\u003e http.get(`/company/${project.companyId}`),\n    (company, project, user) =\u003e http.get(`/brand/${company.brandId}`)\n).subscribe(([brand, company, project, user]) =\u003e console.log(brand, company, project, user));\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/utils/switch-chain.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/utils/switch-chain.spec.ts)] [[up](#utilities)]\n\n----\n### toObservable\n\nConverts the parameter to an observable, or returns the value if already an observable.\n\n```typescript\ntoObservable\u003cT\u003e(value: T | Observable\u003cT\u003e): Observable\u003cT\u003e\n```\n\nExample:\n\nAn example where an array of values is converted into an array of observables.\n\n```typescript\nconst values = [100, of(200), 300];\nforkJoin(values.map(toObservable))\n    .subscribe(v =\u003e console.log(v));\n// prints [100, 200, 300]\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/utils/to-observable.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/utils/to-observable.spec.ts)] [[up](#utilities)]\n\n----\n### windowResize\n\nEmits changes in the window size with optional debounce time.\n\n```typescript\nwindowResize(debounce?: number, wnd?: Window): Observable\u003c{ innerWidth: number, innerHeight: number }\u003e\n```\n\nExample:\n\nCreates an observable of the window aspect ratio.\n\n```typescript\nconst aspect$ = windowResize(250).pipe(\n   map(({innerWidth, innerHeight}) =\u003e innerWidth / innerHeight)\n);\n```\n\n[[source](https://github.com/reactgular/observables/blob/master/src/utils/window-resize.ts)] [[tests](https://github.com/reactgular/observables/blob/master/src/utils/window-resize.spec.ts)] [[up](#utilities)]\n\n----\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactgular%2Fobservables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactgular%2Fobservables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactgular%2Fobservables/lists"}