Skip to content

Instantly share code, notes, and snippets.

@jonaswide
Last active January 24, 2018 12:36
Show Gist options
  • Save jonaswide/f3cc3fbf2ab4ef219605a19237c01b90 to your computer and use it in GitHub Desktop.
Save jonaswide/f3cc3fbf2ab4ef219605a19237c01b90 to your computer and use it in GitHub Desktop.

Revisions

  1. jonaswide revised this gist Jan 24, 2018. 1 changed file with 24 additions and 1 deletion.
    25 changes: 24 additions & 1 deletion concat-curryer.js
    Original 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" }]
    })
    })
  2. jonaswide created this gist Jan 24, 2018.
    5 changes: 5 additions & 0 deletions concat-curryer.js
    Original 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]
    }