fkit
fkit is a small javascript utility that aid in functional programming in javascript.
It consists of the following utilities:
- get/mget
- memoize
- curry
- identity
- map
get/mget
get is a simple field getter for object literal data. It can be used to create reusable functions that access path that might be empty.
; const order = ... /* assumming order has a structure order = { product: { code: 'XY123' } }; and product can be null*/if order && orderproduct return orderproductcode; /** using get*/const getProductCode = ;const code = ;
Note that mget is a same as get but is memoized
memoize
A simple helper to create simple memoized functions. This assume that the function is a pure function. memoize takes in 2 arguments, 1. the function to memoize, 2.(optional) The function that can be used to generate a key. By default memoize will use the first argument as a key.
; const translateCompute = ; ;
compose
Compose is a standard right to left compose.
; const getOrder = ;const getProduct = ;const getDeliveryInfo = ; const getOrderProduct = ;const getOrderDeliveryInfo = ; ; // { id: '123' }; // { address: '123' }