Skip to content

Latest commit

 

History

History
214 lines (135 loc) · 9.66 KB

README.md

File metadata and controls

214 lines (135 loc) · 9.66 KB

@luxcium/boxed-list v0.0.0-PRE_ALPHA-v0.0x

Development phase: No documentation, no tests, full TypeScript support.

MIT Style License

Copyright © 2022 Benjamin Vincent Kasapoglu (Luxcium)

† Scientia est lux principium✨ ™

Installation

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

APIs

Abstract (summary)

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:

Box<T>

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 any TVal 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 the IUnbox<T> interface and the unbox instance method. it can contain any TVal 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 the R 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 the Box<R> type and the chain itself will return a value of the Box<R> type.

BoxedList

DOCUMENTATION INCOMPLE ― WORK IN PROGRESS

BoxedGenerator

DOCUMENTATION INCOMPLE ― WORK IN PROGRESS