Skip to content

Instantly share code, notes, and snippets.

@iest
Last active December 4, 2024 05:24
Show Gist options
  • Save iest/69c6b0fe0dac14b0916ce57b56d9c209 to your computer and use it in GitHub Desktop.
Save iest/69c6b0fe0dac14b0916ce57b56d9c209 to your computer and use it in GitHub Desktop.

Revisions

  1. iest revised this gist Apr 23, 2018. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -87,13 +87,26 @@ Good news is we're only using `lodash/fp`, which makes it easier to match functi
    - `_.values(object)`
    - `R.values` `{k: v} → [v]`
    - 2 x **`takeRight`**
    - `_.takeRight(array, [n=1])`
    - `R.takeLast`
    - 2 x **`take`**
    - `R.take`
    - 2 x **`split`**
    - `R.split`
    - 2 x **`merge`**
    - Deep merge from left to right
    - `R.mergeDeepLeft`
    - 2 x **`memoize`**
    - No equivalent
    - 2 x **`inRange`**
    - `_.inRange(number, [start=0], end)`
    - Checks if n is between start and up to, but not including, end. If end is not specified, it's set to start with start then set to 0. If start is greater than end the params are swapped to support negative ranges.
    - No direct equivalent
    - `R.both(R.gte(R.__, start), R.lte(R.__, end))`
    - 2 x **`includes`**
    - `R.contains`
    - 2 x **`groupBy`**
    -
    - 2 x **`getOr`**
    - 2 x **`concat`**
    - `R.concat`
  2. iest revised this gist Apr 20, 2018. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -81,7 +81,11 @@ Good news is we're only using `lodash/fp`, which makes it easier to match functi
    );
    ```
    - 3 x **`compose`**
    - Alias of `flowRight`
    - `R.compose`
    - 2 x **`values`**
    - `_.values(object)`
    - `R.values` `{k: v} → [v]`
    - 2 x **`takeRight`**
    - 2 x **`take`**
    - 2 x **`split`**
  3. iest revised this gist Apr 20, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -74,7 +74,7 @@ Good news is we're only using `lodash/fp`, which makes it easier to match functi
    - Lodash FP's 3-arity version of `range`
    - `_.rangeStep(step, start, end)`
    - No direct equivalent, closest would be:
    ```
    ```js
    const rangeStep = (start, step, stop) => R.map(
    n => start + step * n,
    R.range(0, (1 + (stop - start) / step) >>> 0)
  4. iest revised this gist Apr 20, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -74,10 +74,12 @@ Good news is we're only using `lodash/fp`, which makes it easier to match functi
    - Lodash FP's 3-arity version of `range`
    - `_.rangeStep(step, start, end)`
    - No direct equivalent, closest would be:
    ```
    const rangeStep = (start, step, stop) => R.map(
    n => start + step * n,
    R.range(0, (1 + (stop - start) / step) >>> 0)
    );
    ```
    - 3 x **`compose`**
    - 2 x **`values`**
    - 2 x **`takeRight`**
  5. iest revised this gist Apr 20, 2018. 1 changed file with 5 additions and 7 deletions.
    12 changes: 5 additions & 7 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -73,13 +73,11 @@ Good news is we're only using `lodash/fp`, which makes it easier to match functi
    - 3 x **`rangeStep`**
    - Lodash FP's 3-arity version of `range`
    - `_.rangeStep(step, start, end)`
    - No direct equivalent, closest would be
    - ```
    const rangeStep = (start, step, stop) => R.map(
    n => start + step * n,
    R.range(0, (1 + (stop - start) / step) >>> 0)
    );
    ```
    - No direct equivalent, closest would be:
    const rangeStep = (start, step, stop) => R.map(
    n => start + step * n,
    R.range(0, (1 + (stop - start) / step) >>> 0)
    );
    - 3 x **`compose`**
    - 2 x **`values`**
    - 2 x **`takeRight`**
  6. iest revised this gist Apr 20, 2018. 1 changed file with 34 additions and 1 deletion.
    35 changes: 34 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -35,18 +35,51 @@ Good news is we're only using `lodash/fp`, which makes it easier to match functi
    - `R.range` `Number → Number → [Number]`
    - Does not support steps
    - 9 x **`findIndex`**
    -
    - `_.findIndex(predicate, array)`
    - `R.findIndex` `(a → Boolean) → [a] → Number`
    - 8 x **`some`**
    - `_.some(predicate, collection)`
    - `R.anyPass` `[(*… → Boolean)] → (*… → Boolean)`
    - 8 x **`map`**
    - `_.map(iteratee, collection)`
    - `R.map` `Functor f => (a → b) → f a → f b`
    - 7 x **`flow`**
    - `_.flow(funcs)`
    - `R.pipe`
    - 7 x **`first`**
    - Alias of `_.head`
    - `R.head`
    - 6 x **`last`**
    - `_.last(array)`
    - `R.last`
    - 5 x **`isEqual`**
    - `_.isEqual(value, other)`
    - `R.equals` `a → b → Boolean`
    - 5 x **`filter`**
    - `R.filter`
    - 5 x **`every`**
    - `_.every(predicate, collection)`
    - predicate called with (value, key|index, collection)
    - `R.all`
    - predicate called with (value)
    - 4 x **`pick`**
    - `_.pick(props, object)`
    - `R.pick` `[k] → {k: v} → {k: v}`
    - 3 x **`reduce`**
    - `_.reduce(iteratee, accumulator, collection)`
    - iteratee is invoked with four arguments: (accumulator, value, index|key, collection)
    - `R.reduce` `((a, b) → a) → a → [b] → a`
    - iterator function receives two values: (acc, value)
    - 3 x **`rangeStep`**
    - Lodash FP's 3-arity version of `range`
    - `_.rangeStep(step, start, end)`
    - No direct equivalent, closest would be
    - ```
    const rangeStep = (start, step, stop) => R.map(
    n => start + step * n,
    R.range(0, (1 + (stop - start) / step) >>> 0)
    );
    ```
    - 3 x **`compose`**
    - 2 x **`values`**
    - 2 x **`takeRight`**
  7. iest revised this gist Apr 19, 2018. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Moving to ramda from lodash
    # Moving from lodash/fp to ramda

    ## How

    @@ -23,11 +23,19 @@ Good news is we're only using `lodash/fp`, which makes it easier to match functi
    - 16 x **`curry`**
    - `R.curry`
    - 13 x **`get`**
    - `R.path`
    - NOTE: ramda paths use arrays, not strings
    - 13 x **`debounce`**
    - No equivalent
    - 12 x **`find`**
    - `_.find(collection, [predicate=_.identity], [fromIndex=0])`
    - `R.find` `(a → Boolean) → [a] → a | undefined`
    - 11 x **`range`**
    - `_.range([start=0], end, [step=1])`
    - `R.range` `Number → Number → [Number]`
    - Does not support steps
    - 9 x **`findIndex`**
    -
    - 8 x **`some`**
    - 8 x **`map`**
    - 7 x **`flow`**
  8. iest revised this gist Apr 19, 2018. 1 changed file with 72 additions and 71 deletions.
    143 changes: 72 additions & 71 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -14,80 +14,81 @@ Good news is we're only using `lodash/fp`, which makes it easier to match functi
    - `import R from 'ramda'`
    - Use as `R.X`, instead of `import { X } from 'ramda'`

    ## Currently used lodash methods:
    - **`assign`**
    - `_.assign(object, [sources])`
    - `R.merge` `{k: v} → {k: v} → {k: v}`
    - **`ceil`**
    - `_.ceil(number, [precision=0])`
    ## Currently used lodash methods with usage:
    - 245 x **`noop`**
    - No equivalent
    - Use `Math.ceil` instead
    - **`clamp`**
    - `_.clamp(number, [lower], upper)`
    - `R.clamp` `Ord a => a → a → a → a`
    - **`compose`**
    - Alias to `flowRight`
    - 62 x **`flowRight`**
    - `R.compose`
    - **`concat`**
    - `R.concat`
    - **`curry`**
    - 26 x **`identity`**
    - 16 x **`curry`**
    - `R.curry`
    - **`curryN`**
    - `R.curryN`
    - **`debounce`**
    - 13 x **`get`**
    - 13 x **`debounce`**
    - No equivalent
    - **`defaultTo`**
    - `R.defaultTo`
    - **`delay`**
    - 12 x **`find`**
    - 11 x **`range`**
    - 9 x **`findIndex`**
    - 8 x **`some`**
    - 8 x **`map`**
    - 7 x **`flow`**
    - 7 x **`first`**
    - 6 x **`last`**
    - 5 x **`isEqual`**
    - 5 x **`filter`**
    - 5 x **`every`**
    - 4 x **`pick`**
    - 3 x **`reduce`**
    - 3 x **`rangeStep`**
    - 3 x **`compose`**
    - 2 x **`values`**
    - 2 x **`takeRight`**
    - 2 x **`take`**
    - 2 x **`split`**
    - 2 x **`merge`**
    - 2 x **`memoize`**
    - 2 x **`inRange`**
    - 2 x **`includes`**
    - 2 x **`groupBy`**
    - 2 x **`getOr`**
    - 2 x **`concat`**
    - `R.concat`
    - 2 x **`clamp`**
    - `_.clamp(number, [lower], upper)`
    - `R.clamp` `Ord a => a → a → a → a`
    - 1 x **`uniqBy`**
    - 1 x **`uniq`**
    - 1 x **`toPairs`**
    - 1 x **`toLower`**
    - 1 x **`throttle`**
    - 1 x **`spread`**
    - 1 x **`sortBy`**
    - 1 x **`slice`**
    - 1 x **`set`**
    - 1 x **`reverse`**
    - 1 x **`replace`**
    - 1 x **`reject`**
    - 1 x **`pluck`**
    - 1 x **`pickBy`**
    - 1 x **`negate`**
    - 1 x **`join`**
    - 1 x **`isObject`**
    - 1 x **`isEmpty`**
    - 1 x **`intersection`**
    - 1 x **`fromPairs`**
    - 1 x **`flatten`**
    - 1 x **`equals`**
    - Alias of `isEquals`
    - `R.equals`
    - 1 x **`delay`**
    - No equivalent
    - Use `setTimeout`
    - **`equals`**
    - **`every`**
    - **`filter`**
    - **`find`**
    - **`findIndex`**
    - **`first`**
    - **`flatten`**
    - **`flow`**
    - **`flowRight`**
    - **`fromPairs`**
    - **`get`**
    - **`getOr`**
    - **`groupBy`**
    - **`identity`**
    - **`includes`**
    - **`inRange`**
    - **`intersection`**
    - **`isEmpty`**
    - **`isEqual`**
    - **`isObject`**
    - **`join`**
    - **`last`**
    - **`map`**
    - **`memoize`**
    - **`merge`**
    - **`negate`**
    - **`noop`**
    - **`pick`**
    - **`pickBy`**
    - **`pluck`**
    - **`range`**
    - **`rangeStep`**
    - **`reduce`**
    - **`reject`**
    - **`replace`**
    - **`reverse`**
    - **`set`**
    - **`slice`**
    - **`some`**
    - **`sortBy`**
    - **`split`**
    - **`spread`**
    - **`take`**
    - **`takeRight`**
    - **`throttle`**
    - **`toLower`**
    - **`toPairs`**
    - **`uniq`**
    - **`uniqBy`**
    - **`values`**
    - 1 x **`defaultTo`**
    - 1 x **`curryN`
    - `R.curryN`
    - 1 x **`ceil`**
    - `_.ceil(number, [precision=0])`
    - No equivalent
    - Use `Math.ceil` instead
    - 1 x **`assign`**
    - `_.assign(object, [sources])`
    - `R.merge` `{k: v} → {k: v} → {k: v}`
  9. iest created this gist Apr 19, 2018.
    93 changes: 93 additions & 0 deletions readme.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,93 @@
    # Moving to ramda from lodash

    ## How

    Good news is we're only using `lodash/fp`, which makes it easier to match function signatures.

    1. Find most-used lodash methods, we'll convert these first maybe?
    1. Go through each lodash method, find the ramda equivalent where possible
    1. Write a codemod to rewrite those usages
    1. Who the fuck thought function aliases were a good idea

    ## Codemod

    - `import R from 'ramda'`
    - Use as `R.X`, instead of `import { X } from 'ramda'`

    ## Currently used lodash methods:
    - **`assign`**
    - `_.assign(object, [sources])`
    - `R.merge` `{k: v} → {k: v} → {k: v}`
    - **`ceil`**
    - `_.ceil(number, [precision=0])`
    - No equivalent
    - Use `Math.ceil` instead
    - **`clamp`**
    - `_.clamp(number, [lower], upper)`
    - `R.clamp` `Ord a => a → a → a → a`
    - **`compose`**
    - Alias to `flowRight`
    - `R.compose`
    - **`concat`**
    - `R.concat`
    - **`curry`**
    - `R.curry`
    - **`curryN`**
    - `R.curryN`
    - **`debounce`**
    - No equivalent
    - **`defaultTo`**
    - `R.defaultTo`
    - **`delay`**
    - No equivalent
    - Use `setTimeout`
    - **`equals`**
    - **`every`**
    - **`filter`**
    - **`find`**
    - **`findIndex`**
    - **`first`**
    - **`flatten`**
    - **`flow`**
    - **`flowRight`**
    - **`fromPairs`**
    - **`get`**
    - **`getOr`**
    - **`groupBy`**
    - **`identity`**
    - **`includes`**
    - **`inRange`**
    - **`intersection`**
    - **`isEmpty`**
    - **`isEqual`**
    - **`isObject`**
    - **`join`**
    - **`last`**
    - **`map`**
    - **`memoize`**
    - **`merge`**
    - **`negate`**
    - **`noop`**
    - **`pick`**
    - **`pickBy`**
    - **`pluck`**
    - **`range`**
    - **`rangeStep`**
    - **`reduce`**
    - **`reject`**
    - **`replace`**
    - **`reverse`**
    - **`set`**
    - **`slice`**
    - **`some`**
    - **`sortBy`**
    - **`split`**
    - **`spread`**
    - **`take`**
    - **`takeRight`**
    - **`throttle`**
    - **`toLower`**
    - **`toPairs`**
    - **`uniq`**
    - **`uniqBy`**
    - **`values`**