0.13.0-beta.6 • Published 8 years ago

fp-stdlib v0.13.0-beta.6

Weekly downloads
-
License
ISC
Repository
-
Last release
8 years ago

fp-stdlib

Build Status Coverage Status

Stdlib is a lightweight library meant to fill the gap between Ramda (functional) and Lodash (performance). All functions are auto-curried and expect data as the last argument to encourage composition.

Stdlib vs. Ramda vs. Lodash

CategoryStdlibRamdaLodashLodash-FP
Minified (kb)6.3841.166.876.6
100% ImmutableYesYesNoYes
Auto-CurryYesYesNoYes
Object EqualityReferenceValueReferenceReference
IE 9+YesYesYesYes

Benchmarks

Each benchmark is measured by the tested operation being performed 10,000 times. The results are in ms. Take these with a grain of salt, they are currently just based off of results from a local Node v6 environment.

FunctionParametersStdlibRamdaLodashLodash-FP
filter10,000 items29527913691365
find10,000 items706313334480
findLast10,000 items626212134155
map10,000 items160843180183
reduce10,000 items1086357135150
scan10,000 items524577----
sum10,000 items778524882884
takeWhile10,000 items138743407392

Comparisons

Stdlib vs. Ramda

To be continued...

Stdlib vs. Lodash

Lodash is extremely popular for good reason; it is renowned for its incredibly performance and exceptionally ergonomic API. We'll touch on both of these separately as we compare it against Stdlib.

Graceful Null Checking

Graceful null checking is the concept that you can provide a null, undefined, or otherwise bad value to a function and not cause it throw at runtime. This feature is beloved by many JavaScript developers since it eliminates one of the biggest sources of pain caused by the language's dynamic nature. Its ommission from Stdlib is not accidental; Lodash's null checking solution, in my opinion, the wrong solution to the problem.

Lodash's graceful handling of null values serves to prevent runtime errors, but does so silently -- this is the key. I instead argue that users should be more explicit about edge cases and handle them opaquely (this is also where Functors start to shine since they essentially encapsulate this logic inside of a type).

Function Shorthands

Concerning shorthand syntax, in my experience I've found it to be more sane to keep API surface area as small as possible, and this means avoiding polymorphic and overloaded functions. By limiting the number of different ways a function can be applied, we implicitly standardize code styles and limit the amount of "magic" in the codebase.

Design Philosophy

Lodash's functional build, coined lodash-fp, does a great job at trying to pull Lodash back into the functional world. However, there are a few areas where it is lacking. First, it is simply a transformed version of lodash core. This makes sense, since it wouldn't be wise to rewrite Lodash in its entirity and maintain the two separately; however, what this means is that it is a second class citizen. It lacks sufficient documentation, instead opting to describe how lodash core is transformed to lodash-fp, which is lacking as a reference resource.

Recommendations

Lodash will always be a more comprehensive library than Stdlib. If you are looking for a full functional replacement, or a functional library that offers similar shorthand methods, Stdlib is not it.

To be continued...