![GitHub license](https://img.shields.io/github/license/nicholasjpaterno/mafp?style=for-the-badge)
MaFP
Map
object with native filter
, map
,reduce
, every
, and some
methods. Zero Dependencies.
https://www.npmjs.com/package/mafp
Motivation
Maps don’t have these methods natively. One would first need to copy an iterator into an array [...iterator]
before using .map
, .filter
, .reduce
. MaFP allows you to use those methods natively.
Installation
npm install mafp
OR
yarn add mafp
Initialize
Javascript
const MaFP = require("mafp").default;
const test = new MaFP([
["A", true],
["B", false],
["C", true],
["D", true],
]);
TypeScript
import MaFP from "mafp";
const test = new MaFP<string, boolean>();
const test = new MaFP([
["A", true],
["B", false],
["C", true],
["D", true],
]);
Usage
test.filter(val => val);
test.filterToArray(val => val);
test.map(val => !val);
test.mapToArray(val => !val);
test.reduce((acc, curr) => acc + Number(curr), 0);
test.every(val => val);
test.some(val => val);
Also works with .keys()
and .values()
:
test.keys().filter(key => key !== 'B');