Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save anirudh-eka/9c8efe1e73251625b16b2e9714acf721 to your computer and use it in GitHub Desktop.

Select an option

Save anirudh-eka/9c8efe1e73251625b16b2e9714acf721 to your computer and use it in GitHub Desktop.

Revisions

  1. anirudh-eka revised this gist Aug 6, 2018. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion transducerBlogExtractReducersExtractFilterAndMapLogic.js
    Original file line number Diff line number Diff line change
    @@ -9,4 +9,7 @@ const filtering = filterLogic => reducer => (a, x) => {
    } else {
    return a;
    }
    }
    }

    const trance = compose([filtering(x => x > 2), mapping(x => x + 1)]);
    [1, 2, 3].reduce(trance((a, x) => a.concat(x)), []);
  2. anirudh-eka created this gist Aug 6, 2018.
    12 changes: 12 additions & 0 deletions transducerBlogExtractReducersExtractFilterAndMapLogic.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    const mapping = mapLogic => reducer => (a, x) => {
    const transformed = mapLogic(x);
    return reducer(a, transformed)
    }

    const filtering = filterLogic => reducer => (a, x) => {
    if(filterLogic(x)) {
    return reducer(a, x)
    } else {
    return a;
    }
    }