1.0.0 • Published 6 years ago

@vlr/fp-conversion v1.0.0

Weekly downloads
1
License
MIT
Repository
gitlab
Last release
6 years ago

@vlr/fp-conversion

A set of functional conversions.

mapWith

This converts a function with one argument into a function with array of arguments of that type. For example, if you have to make such functions:

function doSmth(a: number): string { // do smth … }

function doSmthForAll(a: number[]): string[] { return a.map(doSmth); }

instead of writing second function, you can make it using mapWith

const doSmthForAll = mapWith(doSmth);

It will also work like this if the first function has several arguments

function doSmth(a: number, b: number): string { // do smth … }

function doSmthForAll(a: number[], b: number): string[] { return a.map(a1 => doSmth(a1, b)); }

You can create that function using the same call to mapWith. Also, in case when there is no need to save the resulting function, it can be just called right away.

function doSmth(a: number, b: number): string { return (a + b).toString(); }

const smth: string[] = mapWith(doSmth)([1, 2, 3], 4); // ["5", "6", "7"]
1.0.0

6 years ago