Development phase: No documentation, no tests, full TypeScript support.
Using pnpm:
$ pnpm add --save-prod @luxcium/parallel-mapping
Using yarn:
$ yarn add --caret @luxcium/parallel-mapping
Using npm:
$ npm add --save-prod @luxcium/parallel-mapping
Array.map() is a very useful function because it let you chain many invocations one after the other.
It would be nice to do such a thing on many other types or to chain other kind of mapping utilities like one that would handle asycronious code unfortunately, it only works with synchronous functions.
A simple workaround for using async map functions is to use Promise.all() or its more tolerant brother Promise.allSettled()
What if such thing would be baked in the box.
We propose you 3 kinds of boxes to handle this usecases:
implements IApply<T>
, IChain<T>
, IMap<T>
, IUnbox<T>
, IBox<T>
, IValue<T>
Box is:
-
An Applicative of type
Box<TVal>
To put something inside a new box use the static method of:
Box.of<string>('chocolates')
where the generic type anotation is optional. it can contain anyTVal
value. -
A From of type
Box<TVal>
An alternative to the of static method to put something inside a new box is to use the static method from:
Box.from<string>(chocolateBox)
where the difference is taht you will need to provide any subBox type that implements theIUnbox<T>
interface and the unbox instance method. it can contain anyTVal
value. -
A Functor and a Map of return type
Box<R>
To interact on the internal value use the instance method map:
box.map<number>(chocolates => chocolates.length)
where the optional generic type anotation is theR
return type of the mapping function. -
An Unbox and a Value of return type
<T>
To extract the contained value of your box you can use the instance method box:
box.unbox()
or tap on it's alias, the instance property value:box.value
after chaining many transformation with map it looks pretty elegant and satifying to tap on the internal value using a property so easely. -
An Apply of return type
Box<R>
To interact with the value inside a given box use a boxed function as the argument to the instance method ap:box.ap(Box.of(chocolates=>chocolates.toUpperCase()))
-
A Chain of return type
Box<R>
The chain instance method chain:
box.chain(chocolates=>Box.of(chocolates.toUpperCase()))
takes one argument, it must be a function which returns a value. This function must return a value of theBox<R>
type and the chain itself will return a value of theBox<R>
type.
DOCUMENTATION INCOMPLE ― WORK IN PROGRESS
DOCUMENTATION INCOMPLE ― WORK IN PROGRESS