Skip to content

tarsinzer/fuzion

Repository files navigation

Fuzion

Runtime implementation of shortcut fusion for JavaScript and TypeScript.


Definition (haskell docs)

Shortcut fusion is an optimizer method that merges some function calls into one. E.g., map f * map g can be substituted by map (f * g), and filter p * filter q can be substituted by filter (\x -> q x && p x). It can also help to remove intermediate data structures. E.g., computing sum [1..n] does not require an explicit list structure, and the expression is actually translated into a simple loop.


API

So far, it supports the following operators:

  • fuzion - performs left-to-right function composition. In some libraries this function is named pipe, sequence.
  • map - applies another function to a list of elements and returns a new result on every element in the calling array.
  • filter - invokes a provided predicate function for each array element and includes it into the result.
  • forEach - executes a provided function once for each array element.
  • take - cuts the length of the produced result. It helps to save operators calls to other operators on array elements that will not be included in the final result.