diff --git a/snippets/flip.md b/snippets/flip.md new file mode 100644 index 000000000..d20bda267 --- /dev/null +++ b/snippets/flip.md @@ -0,0 +1,17 @@ +### Flip + +Flip recieves a function the make the first argument the last + +Returning 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 ) +/* +var a = {} +var b = {test:1} +const mergeInto = flip(Object.assign) +mergeInto(a, b) // == b +Object.assign(b,a) // == b +*/ +``` diff --git a/tag_database b/tag_database index 78da7daaf..79f4a1318 100644 --- a/tag_database +++ b/tag_database @@ -124,3 +124,4 @@ without:array words:string zip:array zipObject:array +flip:adapter \ No newline at end of file