Skip to content

Commit

Permalink
Docs: improve rxjs helper docs (#70)
Browse files Browse the repository at this point in the history
* Update filter-array.md

* Update filter-nil.md

* Update filter-array.md

* Update filter-nil.md
  • Loading branch information
tomer953 committed Sep 18, 2023
1 parent 62bd564 commit 8244855
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
12 changes: 6 additions & 6 deletions docs/src/content/docs/utilities/filter-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ title: filterArray
description: ngxtension/filter-array
---

`filterArray` is a RxJs Helper function used when you need to execute a filtering function on an array.
`filterArray` is an RxJS helper function designed for applying a filtering function to an array.

The following code:

```ts
const myObs = of([1, 2, 3]);
const myResultObs = myObs.pipe(map((arr) => arr.filter((e) => e <= 2)));
const source$ = of([1, 2, 3]);
const filtered$ = source$.pipe(map((arr) => arr.filter((element) => element <= 2)));
```

becomes
can be simplified to:

```ts
const myObs = of([1, 2, 3]);
const myResultObs = myObs.pipe(fitlerArray((e) => e <= 1));
const source$ = of([1, 2, 3]);
const filtered$ = source$.pipe(filterArray((element) => element <= 2));
```
18 changes: 10 additions & 8 deletions docs/src/content/docs/utilities/filter-nil.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ title: filterNil
description: ngxtension/filter-nil
---

`filterNil` is a RxJs Helper function used to filter `undefined` and `null` value inside an observable. This operator return a strongly typed value without `undefined` and `null` Type.
`filterNil` is an RxJS helper function designed to filter out `undefined` and `null` values from an observable. This operator returns a strongly-typed value, excluding `undefined` and `null`.

The following code:

```ts
const myObs = of(undefined, null, 1, undefined);
const myResultObs = myObs.pipe(filter(e => e !== undefined && e !== null));
^? number | undefined | null
const source$ = of(undefined, null, 1, undefined);
const filtered$ = source$.pipe(filter((e) => e !== undefined && e !== null));
// Output: 1
// Type: Observable<number | undefined | null>
```

becomes
can be simplified to:

```ts
const myObs = of(undefined, null, 1, undefined);
const myResultObs = myObs.pipe(filterNil());
^? number
const source$ = of(undefined, null, 1, undefined);
const filtered$ = source$.pipe(filterNil());
// Output: 1
// Type: Observable<number>
```
4 changes: 2 additions & 2 deletions docs/src/content/docs/utilities/map-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: mapArray
description: ngxtension/map-array
---

`mapArray` is a RxJs Helper function used when you need to execute a mapping function to map each element of an array.
`mapArray` is an RxJs Helper function designed for applying a transform/map function to an array.

The following code:

Expand All @@ -12,7 +12,7 @@ const myObs = of([1, 2, 3]);
const myResultObs = myObs.pipe(map((arr) => arr.map((e) => e + 1)));
```

becomes
can be simplified to:

```ts
const myObs = of([1, 2, 3]);
Expand Down

0 comments on commit 8244855

Please sign in to comment.