Merge pull request #305 from skatcat31/feature/adapters/flip
[Feature] Add flip adapter
This commit is contained in:
18
snippets/flip.md
Normal file
18
snippets/flip.md
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
### flip
|
||||||
|
|
||||||
|
Flip takes a function as an argument, then makes the first argument the last
|
||||||
|
|
||||||
|
Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const flip = fn => (...args) => fn(args.pop(), ...args)
|
||||||
|
/*
|
||||||
|
let a = {name: 'John Smith'}
|
||||||
|
let b = {}
|
||||||
|
const mergeFrom = flip(Object.assign)
|
||||||
|
let mergePerson = mergeFrom.bind(a)
|
||||||
|
mergePerson(b) // == b
|
||||||
|
b = {}
|
||||||
|
Object.assign(b, a) // == b
|
||||||
|
*/
|
||||||
|
```
|
||||||
@ -125,3 +125,4 @@ without:array
|
|||||||
words:string
|
words:string
|
||||||
zip:array
|
zip:array
|
||||||
zipObject:array
|
zipObject:array
|
||||||
|
flip:adapter
|
||||||
Reference in New Issue
Block a user