diff --git a/snippets/flip.md b/snippets/flip.md new file mode 100644 index 000000000..91eae77a0 --- /dev/null +++ b/snippets/flip.md @@ -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 +*/ +``` diff --git a/tag_database b/tag_database index c2c5be33f..a8d9016b2 100644 --- a/tag_database +++ b/tag_database @@ -125,3 +125,4 @@ without:array words:string zip:array zipObject:array +flip:adapter \ No newline at end of file