Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/franciscotln/callbag-map-when

Callbag operator that maps over values that satisfies a predicate. AKA filterMap
https://github.com/franciscotln/callbag-map-when

Last synced: 3 months ago
JSON representation

Callbag operator that maps over values that satisfies a predicate. AKA filterMap

Awesome Lists containing this project

README

        

# callbag-map-when

Callbag operator that applies a transformation function only to items that satisfy the predicate function. Works as filter() followed by map() on either pullable or listenable sources.

`npm install callbag-map-when`

## Example

```js
const mapWhen = require('callbag-map-when');
const forEach = require('callbag-for-each');
const fromIter = require('callbag-from-iter');
const pipe = require('callbag-pipe');

pipe(
fromIter([1, 2, 3, 4]),
mapWhen(n => n % 2 === 0, n => n * 10),
forEach((n) => {
console.log(n); // 20
}) // 40
);
```