Last active
January 24, 2018 12:36
-
-
Save jonaswide/f3cc3fbf2ab4ef219605a19237c01b90 to your computer and use it in GitHub Desktop.
Revisions
-
jonaswide revised this gist
Jan 24, 2018 . 1 changed file with 24 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,4 +2,27 @@ export const concatCurryer = pre => cur => { const preToConcat = Array.isArray(pre) ? pre : [pre] const curToConcat = Array.isArray(cur) ? cur : [cur] return [...preToConcat, ...curToConcat] } // Examples const arr1 = [{ val: "a" }, { val: "b" }] const arr2 = [{ val: "c" }, { val: "d" }] const obj1 = { val: 1 } const obj2 = { val: 2 } concatCurryer(arr1)(arr2) // [{ val: "a" }, { val: "b" }, { val: "c" }, { val: "d" }] concatCurryer(obj1)(obj2) // [{ val: 1 }, { val: 2 }] concatCurryer(arr1)(obj1) // [{ val: "a" }, { val: "b" }, { val: 1 }] axios("http://some/api") .then(firstResult => { const firstResp = firstResult.data // { val: "first" } const concatter = concatCurryer(firstResp) axios(`http://some/other/api/${firstResp.val}`) .then(secondResult => { const secondResp = secondResult.data // { val: "second" } return concatter(secondResult.data) // [{ val: "first" }, { val: "second" }] }) }) -
jonaswide created this gist
Jan 24, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ export const concatCurryer = pre => cur => { const preToConcat = Array.isArray(pre) ? pre : [pre] const curToConcat = Array.isArray(cur) ? cur : [cur] return [...preToConcat, ...curToConcat] }