
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Functional Utilties for Javascript.
See this talk for motivation and some good examples. http://www.slideshare.net/drboolean/pointfree-functional-programming-in-javascript Code Samples
There are two main concepts this library uses. Currying (or partial application), and Point-free code, or higher-order programming
We can do some powerful stuff by writing functions that create other functions.
TODO: add example
To define a function, we don't always have to actually make a function. Instead, we can rename an existing function. For example:
TODO: add example
TODO: add example
Allows you to easily curry functions. This means that if you call the curried version of a function with fewer arguments that it requires, it returns a function to call with the remaining arguments. The function short-circuits if you call it with the correct number of arguments, meaning that it doesn't affect performance unless it has to.
See: http://en.wikipedia.org/wiki/Currying
The syntax looks best in coffeescript, because you can just prefix a function definition with curry.
curry = require('fjs').curry
# just wrap your function in curry() and it will do the rest
add = curry (a, b) -> a + b
add2 = add(2)
assert.equal add(2,3), 5
assert.equal add2(3), 5
assert.equal add(2)(3), 5
assert.deepEqual [1,2,3].map(add(2)), [3,4,5]
You can also use curry
on a whole module, making it easy to work with functions that haven't been declared as curried. It curry any module functions it finds. Since curry doesn't have any effect when the function is called with all arguments, it doens't hurt anything to do this.
math = curry require('math')
add2 = math.add(2)
We need some simple functions so we can call object actions as functions instead of doing it with a "."
// get
getName = get 'name'
getName(obj) == obj.name
// set
setNameIsBob = set 'name', 'bob'
setNameIsBob(obj)
obj.name = 'bob'
// call
getName = call 'getName'
getName(obj) == obj.getName()
TODO: add example of application on set/call
TODO: basics (eq, etc), and why. Example of why it's useful
Underscore.js is awesome, but it puts the data first. For example, underscore.map
is of type: (list, iterator) ->
. This makes it nearly impossible to do point-free javascript. They're also not curried. For this reason, the following functions are taken from underscore, but they have their data last
Their types are all the same:
find(iterator, list)
You can curry these, for example:
add2 = (n) -> n + 2
add2ToEverything = map add2
add2ToEverything [1,2,3]
We also export the following as-is for convenience
FAQs
Utilities for Functional Javascript
The npm package fjs receives a total of 17 weekly downloads. As such, fjs popularity was classified as not popular.
We found that fjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.