Omnimap
Map over multiple arrays/object without thinking too much. Callback function follows the general input arguments of Array.prototype.map
.
Usage
Array
'use strict';const omnimap = ;const result = ;console; // [5, 7, 9];
You can do three arrays as well. Well, just give it any number of arrays, and it'll map through.
'use strict';const omnimap = ;const result = ;console; // [12, 15, 18];
Object
As with all object looping in js, the order of the outcome is not guaranteed.
'use strict';const omnimap = ;const a = a: 1 b: 2 c: 3 ;const b = a: 4 b: 5 c: 6 ;const result = ;console; // { a: 5, b: 7, c: 9 };
For object mapping, we have a convenient tool that converts the result object into a key-less array.
console; // [5, 7, 9];
Optional lazy evaluation
If you don't pass a callback function as the last argument, it will return a evaluator which you can call with a callback.
'use strict';const omnimap = ;const map = ;const result = ;console; // [5, 7, 9];
The real reason why I made this
Promise.
{ return ;} const omnimap = ;const controllers = doSomethingLethal doSomethingLethal doSomethingLethal;const payloads = msg: 'Hello' msg: 'World' msg: '世界' ; const task = ; Promisealltask;
Caveats
- The maximum iteration count is always the
length
of the first enumerable given. Make sure that the length of following enumerables are less than or equal to the length of the first enumerable. It would fail node.js VM (undefined reference errors). - Object mapping returns its own instance,
OmnimapObject
, rather than a plain object. This is to hide.toArray()
method behind the prototype. However, it still is compatible with allObject.prototype
methods. - Because of the Caveat#2, testing methods such as
chai.assert.deepEqual
would fail. You will have to iterate over each key manually, and assert each member individually.