Skip to content

Commit

Permalink
fix: replace contains occurances
Browse files Browse the repository at this point in the history
  • Loading branch information
selfrefactor committed Aug 19, 2019
1 parent d916411 commit 1dc1368
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 59 deletions.
35 changes: 8 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ https://unpkg.com/[email protected]/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)
Expand Down Expand Up @@ -373,24 +373,6 @@ R.concat('foo')('bar') // => 'foobar'

<a href="https://rambda.now.sh?const%20result%20%3D%20R.concat(%5B1%2C%202%5D)(%5B3%2C%204%5D)%20%2F%2F%20%3D%3E%20%5B1%2C%202%2C%203%2C%204%5D%0AR.concat('foo')('bar')%20%2F%2F%20%3D%3E%20'foobar'">Try in REPL</a>

---
#### 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)

<a href="https://rambda.now.sh?const%20result%20%3D%20R.contains(2%2C%20%5B1%2C%202%5D)%20%2F%2F%20%3D%3E%20true%0AR.contains(3%2C%20%5B1%2C%202%5D)%20%2F%2F%20%3D%3E%20false">Try in REPL</a>

---
#### curry

Expand Down Expand Up @@ -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)

<a href="https://rambda.now.sh?const%20result%20%3D%20R.includes(1%2C%20%5B1%2C%202%5D)%20%2F%2F%20%3D%3E%20true%0AR.includes('oo'%2C%20'foo')%20%2F%2F%20%3D%3E%20true%0AR.includes('z'%2C%20'foo')%20%2F%2F%20%3D%3E%20false%0AR.includes('z'%2C%20null)%20%2F%2F%20%3D%3E%20false">Try in REPL</a>
<a href="https://rambda.now.sh?const%20result%20%3D%20R.includes('oo'%2C%20'foo')%20%2F%2F%20%3D%3E%20true%0AR.includes(%7Ba%3A%201%7D%2C%20%5B%7Ba%3A%201%7D%5D)%20%2F%2F%20%3D%3E%20true">Try in REPL</a>

---
#### indexBy
Expand Down Expand Up @@ -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
Expand Down
35 changes: 8 additions & 27 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ https://unpkg.com/[email protected]/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)
Expand Down Expand Up @@ -373,24 +373,6 @@ R.concat('foo')('bar') // => 'foobar'

<a href="https://rambda.now.sh?const%20result%20%3D%20R.concat(%5B1%2C%202%5D)(%5B3%2C%204%5D)%20%2F%2F%20%3D%3E%20%5B1%2C%202%2C%203%2C%204%5D%0AR.concat('foo')('bar')%20%2F%2F%20%3D%3E%20'foobar'">Try in REPL</a>

---
#### 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)

<a href="https://rambda.now.sh?const%20result%20%3D%20R.contains(2%2C%20%5B1%2C%202%5D)%20%2F%2F%20%3D%3E%20true%0AR.contains(3%2C%20%5B1%2C%202%5D)%20%2F%2F%20%3D%3E%20false">Try in REPL</a>

---
#### curry

Expand Down Expand Up @@ -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)

<a href="https://rambda.now.sh?const%20result%20%3D%20R.includes(1%2C%20%5B1%2C%202%5D)%20%2F%2F%20%3D%3E%20true%0AR.includes('oo'%2C%20'foo')%20%2F%2F%20%3D%3E%20true%0AR.includes('z'%2C%20'foo')%20%2F%2F%20%3D%3E%20false%0AR.includes('z'%2C%20null)%20%2F%2F%20%3D%3E%20false">Try in REPL</a>
<a href="https://rambda.now.sh?const%20result%20%3D%20R.includes('oo'%2C%20'foo')%20%2F%2F%20%3D%3E%20true%0AR.includes(%7Ba%3A%201%7D%2C%20%5B%7Ba%3A%201%7D%5D)%20%2F%2F%20%3D%3E%20true">Try in REPL</a>

---
#### indexBy
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion rambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions src/uniq.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/without.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { contains } from './contains'
import { includes } from './includes'
import { reduce } from './reduce'

/**
Expand All @@ -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
)
Expand Down

0 comments on commit 1dc1368

Please sign in to comment.