From 1dc1368f81e9f398664c9d95c2efbc48b5cdff9b Mon Sep 17 00:00:00 2001 From: Dejan Toteff Date: Mon, 19 Aug 2019 20:17:05 +0300 Subject: [PATCH] fix: replace contains occurances --- README.md | 35 ++++++++--------------------------- docs/README.md | 35 ++++++++--------------------------- rambda.js | 1 - src/uniq.js | 4 ++-- src/without.js | 4 ++-- 5 files changed, 20 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index ff583a6f6..36d1bd582 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ https://unpkg.com/rambda@2.0.0/dist/rambda.umd.js - Rambda's **partialCurry** is not part of Ramda API. -- Rambda's **includes** acts as curried Javascript `includes`, while **Ramda** version uses `R.equals` to check if a list contains certain value. Also **Ramda** version will throw an error if input is neither `string` nor `array`, while **Rambda** version will return `false`. +- Ramda's **includes** will throw an error if input is neither `string` nor `array`, while **Rambda** version will return `false`. > If you need more **Ramda** methods in **Rambda**, you may either submit a `PR` or check the extended version of **Rambda** - [Rambdax](https://github.com/selfrefactor/rambdax). In case of the former, you may want to consult with [Rambda contribution guidelines.](CONTRIBUTING.md) @@ -373,24 +373,6 @@ R.concat('foo')('bar') // => 'foobar' Try in REPL ---- -#### contains - -> contains(valueToFind: T, arr: T[]): boolean - -It returns `true`, if `valueToFind` is part of `arr`. - -Note that while new versions of `Ramda` depricate this method, `contains` will remain in this library. - -``` -R.contains(2, [1, 2]) // => true -R.contains(3, [1, 2]) // => false -``` - -[Source](https://github.com/selfrefactor/rambda/tree/master/src/contains.js) - -Try in REPL - --- #### curry @@ -861,22 +843,19 @@ R.inc(1) // => 2 --- #### includes -If `input` is neither `string` nor `array`, then this method will return `false`. +> includes(valueToFind: T|string, input: T[]|string): boolean -> includes(target: any, input: any): boolean +If `input` is string, then this method work as native `includes`. +If `input` is array, then `R.equals` is used to define if `valueToFind` belongs to the list. ``` -R.includes(1, [1, 2]) // => true R.includes('oo', 'foo') // => true -R.includes('z', 'foo') // => false -R.includes('z', null) // => false +R.includes({a: 1}, [{a: 1}]) // => true ``` -!! Note that this method is not part of `Ramda` API. - [Source](https://github.com/selfrefactor/rambda/tree/master/src/includes.js) -Try in REPL +Try in REPL --- #### indexBy @@ -2227,6 +2206,8 @@ import omit from 'rambda/lib/omit' ## Changelog +- 3.0.0 Deprecate `R.contains`, while `R.includes` is now following Ramda API(it uses `R.equals` for comparision) + - 2.14.5 `R.without` needs currying - 2.14.4 Close [issue #227](https://github.com/selfrefactor/rambda/issues/227) - add index as third argument of `R.reduce` typings diff --git a/docs/README.md b/docs/README.md index ff583a6f6..36d1bd582 100644 --- a/docs/README.md +++ b/docs/README.md @@ -111,7 +111,7 @@ https://unpkg.com/rambda@2.0.0/dist/rambda.umd.js - Rambda's **partialCurry** is not part of Ramda API. -- Rambda's **includes** acts as curried Javascript `includes`, while **Ramda** version uses `R.equals` to check if a list contains certain value. Also **Ramda** version will throw an error if input is neither `string` nor `array`, while **Rambda** version will return `false`. +- Ramda's **includes** will throw an error if input is neither `string` nor `array`, while **Rambda** version will return `false`. > If you need more **Ramda** methods in **Rambda**, you may either submit a `PR` or check the extended version of **Rambda** - [Rambdax](https://github.com/selfrefactor/rambdax). In case of the former, you may want to consult with [Rambda contribution guidelines.](CONTRIBUTING.md) @@ -373,24 +373,6 @@ R.concat('foo')('bar') // => 'foobar' Try in REPL ---- -#### contains - -> contains(valueToFind: T, arr: T[]): boolean - -It returns `true`, if `valueToFind` is part of `arr`. - -Note that while new versions of `Ramda` depricate this method, `contains` will remain in this library. - -``` -R.contains(2, [1, 2]) // => true -R.contains(3, [1, 2]) // => false -``` - -[Source](https://github.com/selfrefactor/rambda/tree/master/src/contains.js) - -Try in REPL - --- #### curry @@ -861,22 +843,19 @@ R.inc(1) // => 2 --- #### includes -If `input` is neither `string` nor `array`, then this method will return `false`. +> includes(valueToFind: T|string, input: T[]|string): boolean -> includes(target: any, input: any): boolean +If `input` is string, then this method work as native `includes`. +If `input` is array, then `R.equals` is used to define if `valueToFind` belongs to the list. ``` -R.includes(1, [1, 2]) // => true R.includes('oo', 'foo') // => true -R.includes('z', 'foo') // => false -R.includes('z', null) // => false +R.includes({a: 1}, [{a: 1}]) // => true ``` -!! Note that this method is not part of `Ramda` API. - [Source](https://github.com/selfrefactor/rambda/tree/master/src/includes.js) -Try in REPL +Try in REPL --- #### indexBy @@ -2227,6 +2206,8 @@ import omit from 'rambda/lib/omit' ## Changelog +- 3.0.0 Deprecate `R.contains`, while `R.includes` is now following Ramda API(it uses `R.equals` for comparision) + - 2.14.5 `R.without` needs currying - 2.14.4 Close [issue #227](https://github.com/selfrefactor/rambda/issues/227) - add index as third argument of `R.reduce` typings diff --git a/rambda.js b/rambda.js index ebc5e137a..bf90889a8 100644 --- a/rambda.js +++ b/rambda.js @@ -14,7 +14,6 @@ export * from './src/clone' export * from './src/complement' export * from './src/compose' export * from './src/concat' -export * from './src/contains' export * from './src/curry' export * from './src/dec' export * from './src/defaultTo' diff --git a/src/uniq.js b/src/uniq.js index 2df25a0d0..463dd5e98 100644 --- a/src/uniq.js +++ b/src/uniq.js @@ -1,4 +1,4 @@ -import { contains } from './contains' +import { includes } from './includes' /** * Returns a new list containing only one copy of each element in the original @@ -22,7 +22,7 @@ export function uniq(list){ while (++index < list.length){ const value = list[ index ] - if (!contains(value, willReturn)){ + if (!includes(value, willReturn)){ willReturn.push(value) } } diff --git a/src/without.js b/src/without.js index 495355afa..4653dfd04 100644 --- a/src/without.js +++ b/src/without.js @@ -1,4 +1,4 @@ -import { contains } from './contains' +import { includes } from './includes' import { reduce } from './reduce' /** @@ -24,7 +24,7 @@ export function without(left, right){ return reduce( (accum, item) => - contains(item, left) ? accum : accum.concat(item), + includes(item, left) ? accum : accum.concat(item), [], right )