Merge pull request #305 from skatcat31/feature/adapters/flip

[Feature] Add flip adapter
This commit is contained in:
Stefan Feješ
2017-12-22 15:09:31 +01:00
committed by GitHub
2 changed files with 19 additions and 0 deletions

18
snippets/flip.md Normal file
View 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
*/
```

View File

@ -125,3 +125,4 @@ without:array
words:string words:string
zip:array zip:array
zipObject:array zipObject:array
flip:adapter