From f61648861576f15cd4805d4a7d5cc4fb1c459dff Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Thu, 21 Dec 2017 16:42:15 -0800 Subject: [PATCH 1/5] [Feature] Add flip adapter --- snippets/flip.md | 17 +++++++++++++++++ tag_database | 1 + 2 files changed, 18 insertions(+) create mode 100644 snippets/flip.md 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 From d577114321238b21ab41e4815551f7f699d9184a Mon Sep 17 00:00:00 2001 From: Robert Mennell Date: Thu, 21 Dec 2017 16:47:12 -0800 Subject: [PATCH 2/5] Fix: example was a little wrong --- snippets/flip.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/snippets/flip.md b/snippets/flip.md index d20bda267..02901b34d 100644 --- a/snippets/flip.md +++ b/snippets/flip.md @@ -8,10 +8,12 @@ Returning a closure that takes variadic inputs, and splices the last argument to const flip = fn => (...args) => fn( args.pop(), ...args ) /* -var a = {} -var b = {test:1} -const mergeInto = flip(Object.assign) -mergeInto(a, b) // == b +var a = {name: "John Smith"} +var b = {} +const mergeFrom = flip(Object.assign) +let mergePerson = mergeFrom.bind(a) +mergePerson(b) // == b +b = {} Object.assign(b,a) // == b */ -``` +``` From 7816902f71e7804df48253a5e444d44ed2ed995a Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 22 Dec 2017 09:36:36 +0200 Subject: [PATCH 3/5] Minor formatting --- snippets/flip.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/snippets/flip.md b/snippets/flip.md index 02901b34d..aed551287 100644 --- a/snippets/flip.md +++ b/snippets/flip.md @@ -1,12 +1,11 @@ ### Flip -Flip recieves a function the make the first argument the last +Flip takes a function as an argument, then makes 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 +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 ) +const flip = fn => (...args) => fn( args.pop(), ...args ) /* var a = {name: "John Smith"} var b = {} From 8697fcf87ff58b896c7a95fbd6ff164c0e858303 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 22 Dec 2017 09:43:49 +0200 Subject: [PATCH 4/5] Update flip.md --- snippets/flip.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/flip.md b/snippets/flip.md index aed551287..fa57897b7 100644 --- a/snippets/flip.md +++ b/snippets/flip.md @@ -1,4 +1,4 @@ -### Flip +### flip Flip takes a function as an argument, then makes the first argument the last From 814dd658e41935af07bfc4a8dfc54d8aa309e0dd Mon Sep 17 00:00:00 2001 From: Soorena Date: Fri, 22 Dec 2017 17:34:45 +0330 Subject: [PATCH 5/5] Update flip.md updated formatting --- snippets/flip.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snippets/flip.md b/snippets/flip.md index fa57897b7..91eae77a0 100644 --- a/snippets/flip.md +++ b/snippets/flip.md @@ -5,14 +5,14 @@ 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 ) +const flip = fn => (...args) => fn(args.pop(), ...args) /* -var a = {name: "John Smith"} -var b = {} +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 +Object.assign(b, a) // == b */ ```