mapfunc
-
mapfunc is a function that applies a mapping function to an infinite number of input elements, with options to skip certain elements and selectively apply the mapping to keys and/or values of objects.
-
The mapfunc function has been developed in JavaScript and Python, offering the same functionality in different programming languages.
Install
npm install mapfunc
Import
const mapfunc = require("mapfunc");
import mapfunc from "mapfunc"
unpkg
<script src="https://unpkg.com/mapfunc@latest/index.js"></script>
Syntax
mapfunc(fun,{skip,key,value},...X)
Arguments
fun : The mapping function that will be applied to each element in the input elements.
...X :The elements to be mapped .
{ skip , key , value } : Object with three optional properties :
skip : specifies the elements to skip during the mapping process.
key : boolean flag indicating whether to apply the mapping function to the keys of objects or not. The default value is false
value : boolean flag indicating whether to apply the mapping function to the values of objects or not. The default value is true
Examples
console.log(
mapfunc(n => n + 2,{}, 1,"a", [1, 2, 3], true, {
a: 2,
b: 3,
c: { d: 3, e: [1, 3, 4] },
})
);
const PI=Math.PI
const sin=(...args)=>mapfunc(Math.sin,{},...args)
console.log(sin(0,PI/4,[0,PI/6,PI/4,{x:PI/8,y:PI/12}]))
Advanced Examples
const A=new Map([["a",1],["b",2]]);
console.log(mapfunc(n=>n+1,{},A));
console.log(mapfunc(n=>n+1,{key:true},A));
console.log(mapfunc(n=>n+1,{value:false},A));
console.log(mapfunc(n=>n+1,{key:true,value:false},A));
License
This projet is licensed under the terms of MIT License .
