0.3.1 • Published 8 years ago

compact-map v0.3.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

maps and compacts at the same time.

By default compactMap filters out null and undefined but perserves falsy values.

Example 1:

compactMap(
    [{foo: 0}, {foo: 'truthy'}, {foo: null}, {foo: undefined}],
    (value, index, coll) => value.foo
)

returns:

[0, 'truthy']

Note that the compacting logic operates on the the return value from the mapping callback, not the original value in the source collection.

Example 2:

compactMap(
    [undefined, null, false],
    (value, index, coll) => value + ' mapped'
)
```
returns:
```
['undefined mapped', 'null mapped', 'false mapped']
```


To remove falsy values as well, pass in the options object: `{strict: true}`.

Example:
```
compactMap(
    [{foo: 0}, {foo: 'truthy'}, {foo: null}, {foo: undefined}],
    (value, index, coll) => value.foo,
    { strict: true }
)
```
returns:
`['truthy']`
0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago