This repository was archived by the owner on Jan 8, 2020. It is now read-only.
v1.6.0
All new features have been added to the online playground!
This release adds positional placeholders! Sometimes called swizzle or rearg,
you can partially apply arguments in a different order than the function normally
accepts, or use a single argument multiple times.
Let's say you want to reorder the arguments of lodash.get()
, which normally has
a signature of object, path, defaultValue
, to path, defaultValue, object
:
// forget that lodash/fp even exists for a second :)
import { get } from 'lodash'
// reorder the arguments so the data is accepted last
const getFunctional = get(_`3`, _`1`, _`2`)
getFunctional('color', 'blue', { color: 'green' })
// -> 'green'
You can also use positional placeholders to reuse a single argument, for example
to create a function checking if something is equal to itself ( NaN
never is ):
const isSameThing = _`1` === _`1`
isSameThing('yes!')
// -> true
isSameThing(NaN)
// -> false
Features
- add positional placeholder syntax (dbc9f9f)
Bug fixes
- fix mid-chain properties in applied call arguments being compiled if they look like a placeholder (6bc3d01)
- track custom tokens per file to prevent leaks into others, breaking their placeholders (2e39c99)
Playground
The playground got a few UI & UX improvements:
- 'send to editor' buttons on all JS code blocks for easily trying out the examples
- a 'go to top' button in the readme when you've scrolled down
- better URL handling (used for linking to the readme and specific sections of it)