0.0.2 • Published 5 years ago

@sullux/fp-light-filter v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

home

fp-light-filter

npm i @sullux/fp-light-filter source test

The filter function works similarly to the built in Array.prototype.filter function except that the iterable is the most significant (last) argument.

filter

filter(test: Function, iterator: Iterator<mixed>): Iterator<mixed>

The advantage to using iterable functions like filter over the built-in array functions is that the array functions create an intermediate representation where the iterable functions evaluate lazily. This leads to a lower memory footprint and faster processing in many scenarios.

This example uses the filter and map iterable functions.

const { filter } = require('@sullux/fp-light-filter')
const { get } = require('@sullux/fp-light-get')
const { pipe } = require('@sullux/fp-light-pipe')
const { trap } = require('@sullux/fp-light-trap')
const { readFile, readdir } = require('fs')
const { promisify } = require('util')

const readAllObjects = pipe(
  promisify(readdir),
  map(get('toString')),
  map(trap(promisify(readFile))),
  filter(get(1)),
  map(get(1, 'toString')),
  map(JSON.parse),
  Promise.all,
)

module.exports = { readAllObjects }
0.0.2

5 years ago

0.0.1

5 years ago