Skip to content

Commit 20d3243

Browse files
committed
rename exists to isSomeAnd like Rust
1 parent 7d171cc commit 20d3243

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

src/Core__Option.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function cmp(a, b, f) {
106106
}
107107
}
108108

109-
function exists(o, p) {
109+
function isSomeAnd(o, p) {
110110
if (o !== undefined) {
111111
return Curry._1(p, Caml_option.valFromOption(o));
112112
} else {
@@ -135,7 +135,7 @@ export {
135135
isNone ,
136136
eq ,
137137
cmp ,
138-
exists ,
138+
isSomeAnd ,
139139
isNoneOr ,
140140
}
141141
/* No side effect */

src/Core__Option.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ let cmpU = (a, b, f) =>
112112

113113
let cmp = (a, b, f) => cmpU(a, b, (. x, y) => f(x, y))
114114

115-
let exists = (o, p) =>
115+
let isSomeAnd = (o, p) =>
116116
switch o {
117117
| None => false
118118
| Some(v) => p(v)

src/Core__Option.resi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,19 @@ cmp(None, None, clockCompare) // 0
250250
let cmp: (option<'a>, option<'b>, ('a, 'b) => int) => int
251251

252252
/**
253-
`exists(option, predicate)` tests whether the option is `Some` **and** the predicate applied to its value is true.
253+
`isSomeAnd(option, predicate)` tests whether the option is `Some` **and** the predicate applied to its value is true.
254254
255-
An option can be thought of as an array with 0 or 1 items in it. `exists` is similar to `Array.some` and acts like the "there exists" quantifier in mathematics. It returns false for a `None` option.
255+
An option can be thought of as an array with 0 or 1 items in it. `isSomeAnd` is similar to `Array.some` and acts like the "there exists" quantifier in mathematics. It returns false for a `None` option.
256256
257257
## Examples
258258
259259
```rescript
260-
Option.exists(None, i => i >= 0) // false
261-
Option.exists(Some(3), i => i > 1) // true
262-
Option.exists(Some(3), i => i < 0) // false
260+
Option.isSomeAnd(None, i => i >= 0) // false
261+
Option.isSomeAnd(Some(3), i => i > 1) // true
262+
Option.isSomeAnd(Some(3), i => i < 0) // false
263263
```
264264
*/
265-
let exists: (option<'a>, 'a => bool) => bool
265+
let isSomeAnd: (option<'a>, 'a => bool) => bool
266266

267267
/**
268268
`isNoneOr(option, predicate)` tests whether the option is `None` **or** the predicate applied to its value is true.

test/OptionTests.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,37 @@ function isPositive(i) {
1313
Test.run([
1414
[
1515
"OptionTests.res",
16-
11,
17-
20,
18-
51
16+
12,
17+
13,
18+
47
1919
],
20-
"exists: if None, return false"
21-
], Core__Option.exists(undefined, isPositive), eq, false);
20+
"isSomeAnd: if None, return false"
21+
], Core__Option.isSomeAnd(undefined, isPositive), eq, false);
2222

2323
Test.run([
2424
[
2525
"OptionTests.res",
26-
14,
26+
19,
2727
13,
2828
52
2929
],
3030
"exists: if Some and true, return true"
31-
], Core__Option.exists(1, isPositive), eq, true);
31+
], Core__Option.isSomeAnd(1, isPositive), eq, true);
3232

3333
Test.run([
3434
[
3535
"OptionTests.res",
36-
21,
36+
26,
3737
13,
3838
54
3939
],
4040
"exists: if Some and false, return false"
41-
], Core__Option.exists(-1, isPositive), eq, false);
41+
], Core__Option.isSomeAnd(-1, isPositive), eq, false);
4242

4343
Test.run([
4444
[
4545
"OptionTests.res",
46-
27,
46+
32,
4747
20,
4848
52
4949
],
@@ -53,7 +53,7 @@ Test.run([
5353
Test.run([
5454
[
5555
"OptionTests.res",
56-
30,
56+
35,
5757
13,
5858
54
5959
],
@@ -63,7 +63,7 @@ Test.run([
6363
Test.run([
6464
[
6565
"OptionTests.res",
66-
37,
66+
42,
6767
13,
6868
56
6969
],

test/OptionTests.res

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,29 @@ open RescriptCore
22

33
let eq = (a, b) => a == b
44

5-
// ===================
6-
// exists and isNoneOr
7-
// ===================
5+
// ======================
6+
// isSomeAnd and isNoneOr
7+
// ======================
88

99
let isPositive = i => i > 0
1010

11-
Test.run(__POS_OF__("exists: if None, return false"), None->Option.exists(isPositive), eq, false)
11+
Test.run(
12+
__POS_OF__("isSomeAnd: if None, return false"),
13+
None->Option.isSomeAnd(isPositive),
14+
eq,
15+
false,
16+
)
1217

1318
Test.run(
1419
__POS_OF__("exists: if Some and true, return true"),
15-
Some(1)->Option.exists(isPositive),
20+
Some(1)->Option.isSomeAnd(isPositive),
1621
eq,
1722
true,
1823
)
1924

2025
Test.run(
2126
__POS_OF__("exists: if Some and false, return false"),
22-
Some(-1)->Option.exists(isPositive),
27+
Some(-1)->Option.isSomeAnd(isPositive),
2328
eq,
2429
false,
2530
)

0 commit comments

Comments
 (0)