Skip to content

Commit bf50e4e

Browse files
committed
refactor: WithDefault -> Or
1 parent a976a8c commit bf50e4e

12 files changed

Lines changed: 61 additions & 61 deletions

src/Core__Null.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function fromOption(option) {
1111
}
1212
}
1313

14-
function getWithDefault(value, $$default) {
14+
function getOr(value, $$default) {
1515
if (value !== null) {
1616
return value;
1717
} else {
@@ -38,7 +38,7 @@ function map(value, f) {
3838
}
3939
}
4040

41-
function mapWithDefault(value, $$default, f) {
41+
function mapOr(value, $$default, f) {
4242
if (value !== null) {
4343
return Curry._1(f, value);
4444
} else {
@@ -56,10 +56,10 @@ function flatMap(value, f) {
5656

5757
export {
5858
fromOption ,
59-
getWithDefault ,
59+
getOr ,
6060
getExn ,
6161
map ,
62-
mapWithDefault ,
62+
mapOr ,
6363
flatMap ,
6464
}
6565
/* No side effect */

src/Core__Null.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let fromOption: option<'a> => t<'a> = option =>
1414
| None => null
1515
}
1616

17-
let getWithDefault = (value, default) =>
17+
let getOr = (value, default) =>
1818
switch value->toOption {
1919
| Some(x) => x
2020
| None => default
@@ -34,7 +34,7 @@ let map = (value, f) =>
3434
| None => null
3535
}
3636

37-
let mapWithDefault = (value, default, f) =>
37+
let mapOr = (value, default, f) =>
3838
switch value->toOption {
3939
| Some(x) => f(x)
4040
| None => default

src/Core__Null.resi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ Console.log(asNull == null) // Logs `true` to the console.
7373
let fromOption: option<'a> => t<'a>
7474

7575
/**
76-
`getWithDefault(value, default)` returns `value` if not `null`, otherwise return
76+
`getOr(value, default)` returns `value` if not `null`, otherwise return
7777
`default`.
7878
7979
## Examples
8080
8181
```rescript
82-
Null.getWithDefault(null, "Banana") // Banana
83-
Null.getWithDefault(Nulalble.make("Apple"), "Banana") // Apple
82+
Null.getOr(null, "Banana") // Banana
83+
Null.getOr(Nulalble.make("Apple"), "Banana") // Apple
8484
8585
let greet = (firstName: option<string>) =>
86-
"Greetings " ++ firstName->Null.getWithDefault("Anonymous")
86+
"Greetings " ++ firstName->Null.getOr("Anonymous")
8787
8888
Null.make("Jane")->greet // "Greetings Jane"
8989
null->greet // "Greetings Anonymous"
9090
```
9191
*/
92-
let getWithDefault: (t<'a>, 'a) => 'a
92+
let getOr: (t<'a>, 'a) => 'a
9393

9494
/**
9595
`getExn(value)` raises an exception if `null`, otherwise returns the value.
@@ -135,20 +135,20 @@ Null.map(null, x => x * x) // null
135135
let map: (t<'a>, 'a => 'b) => t<'b>
136136

137137
/**
138-
`mapWithDefault(value, default, f)` returns `f(value)` if `value` is not `null`,
138+
`mapOr(value, default, f)` returns `f(value)` if `value` is not `null`,
139139
otherwise returns `default`.
140140
141141
## Examples
142142
143143
```rescript
144144
let someValue = Null.make(3)
145-
someValue->Null.mapWithDefault(0, x => x + 5) // 8
145+
someValue->Null.mapOr(0, x => x + 5) // 8
146146
147147
let noneValue = null
148-
noneValue->Null.mapWithDefault(0, x => x + 5) // 0
148+
noneValue->Null.mapOr(0, x => x + 5) // 0
149149
```
150150
*/
151-
let mapWithDefault: (t<'a>, 'b, 'a => 'b) => 'b
151+
let mapOr: (t<'a>, 'b, 'a => 'b) => 'b
152152

153153
/**
154154
`flatMap(value, f)` returns `f(value)` if `value` is not `null`, otherwise

src/Core__Nullable.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function fromOption(option) {
1010

1111
}
1212

13-
function getWithDefault(value, $$default) {
13+
function getOr(value, $$default) {
1414
if (value == null) {
1515
return $$default;
1616
} else {
@@ -37,7 +37,7 @@ function map(value, f) {
3737
}
3838
}
3939

40-
function mapWithDefault(value, $$default, f) {
40+
function mapOr(value, $$default, f) {
4141
if (value == null) {
4242
return $$default;
4343
} else {
@@ -55,10 +55,10 @@ function flatMap(value, f) {
5555

5656
export {
5757
fromOption ,
58-
getWithDefault ,
58+
getOr ,
5959
getExn ,
6060
map ,
61-
mapWithDefault ,
61+
mapOr ,
6262
flatMap ,
6363
}
6464
/* No side effect */

src/Core__Nullable.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let fromOption: option<'a> => t<'a> = option =>
1414
| None => undefined
1515
}
1616

17-
let getWithDefault = (value, default) =>
17+
let getOr = (value, default) =>
1818
switch value->toOption {
1919
| Some(x) => x
2020
| None => default
@@ -34,7 +34,7 @@ let map = (value, f) =>
3434
| None => Obj.magic(value)
3535
}
3636

37-
let mapWithDefault = (value, default, f) =>
37+
let mapOr = (value, default, f) =>
3838
switch value->toOption {
3939
| Some(x) => f(x)
4040
| None => default

src/Core__Nullable.resi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,23 @@ let asNullable = optString->Nullable.fromOption // Nullable.t<string>
8383
let fromOption: option<'a> => t<'a>
8484

8585
/**
86-
`getWithDefault(value, default)` returns `value` if not `null` or `undefined`,
86+
`getOr(value, default)` returns `value` if not `null` or `undefined`,
8787
otherwise return `default`.
8888
8989
## Examples
9090
9191
```rescript
92-
Nullable.getWithDefault(Nullable.null, "Banana") // Banana
93-
Nullable.getWithDefault(Nulalble.make("Apple"), "Banana") // Apple
92+
Nullable.getOr(Nullable.null, "Banana") // Banana
93+
Nullable.getOr(Nulalble.make("Apple"), "Banana") // Apple
9494
9595
let greet = (firstName: option<string>) =>
96-
"Greetings " ++ firstName->Nullable.getWithDefault("Anonymous")
96+
"Greetings " ++ firstName->Nullable.getOr("Anonymous")
9797
9898
Nullable.make("Jane")->greet // "Greetings Jane"
9999
Nullable.null->greet // "Greetings Anonymous"
100100
```
101101
*/
102-
let getWithDefault: (t<'a>, 'a) => 'a
102+
let getOr: (t<'a>, 'a) => 'a
103103

104104
/**
105105
`getExn(value)` raises an exception if `null` or `undefined`, otherwise returns the value.
@@ -145,20 +145,20 @@ Nullable.map(undefined, x => x * x) // undefined
145145
let map: (t<'a>, 'a => 'b) => t<'b>
146146

147147
/**
148-
`mapWithDefault(value, default, f)` returns `f(value)` if `value` is not `null`
148+
`mapOr(value, default, f)` returns `f(value)` if `value` is not `null`
149149
or `undefined`, otherwise returns `default`.
150150
151151
## Examples
152152
153153
```rescript
154154
let someValue = Nullable.make(3)
155-
someValue->Nullable.mapWithDefault(0, x => x + 5) // 8
155+
someValue->Nullable.mapOr(0, x => x + 5) // 8
156156
157157
let noneValue = Nullable.null
158-
noneValue->Nullable.mapWithDefault(0, x => x + 5) // 0
158+
noneValue->Nullable.mapOr(0, x => x + 5) // 0
159159
```
160160
*/
161-
let mapWithDefault: (t<'a>, 'b, 'a => 'b) => 'b
161+
let mapOr: (t<'a>, 'b, 'a => 'b) => 'b
162162

163163
/**
164164
`flatMap(value, f)` returns `f(value)` if `value` is not `null` or `undefined`,

src/Core__Option.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function getExn(x) {
2929
};
3030
}
3131

32-
function mapWithDefault(opt, $$default, f) {
32+
function mapOr(opt, $$default, f) {
3333
var f$1 = Curry.__1(f);
3434
if (opt !== undefined) {
3535
return f$1(Caml_option.valFromOption(opt));
@@ -54,7 +54,7 @@ function flatMap(opt, f) {
5454

5555
}
5656

57-
function getWithDefault(opt, $$default) {
57+
function getOr(opt, $$default) {
5858
if (opt !== undefined) {
5959
return Caml_option.valFromOption(opt);
6060
} else {
@@ -110,10 +110,10 @@ export {
110110
filter ,
111111
forEach ,
112112
getExn ,
113-
mapWithDefault ,
113+
mapOr ,
114114
map ,
115115
flatMap ,
116-
getWithDefault ,
116+
getOr ,
117117
orElse ,
118118
isSome ,
119119
isNone ,

src/Core__Option.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ let getExn = x =>
4646

4747
external getUnsafe: option<'a> => 'a = "%identity"
4848

49-
let mapWithDefaultU = (opt, default, f) =>
49+
let mapOrU = (opt, default, f) =>
5050
switch opt {
5151
| Some(x) => f(. x)
5252
| None => default
5353
}
5454

55-
let mapWithDefault = (opt, default, f) => mapWithDefaultU(opt, default, (. x) => f(x))
55+
let mapOr = (opt, default, f) => mapOrU(opt, default, (. x) => f(x))
5656

5757
let mapU = (opt, f) =>
5858
switch opt {
@@ -70,7 +70,7 @@ let flatMapU = (opt, f) =>
7070

7171
let flatMap = (opt, f) => flatMapU(opt, (. x) => f(x))
7272

73-
let getWithDefault = (opt, default) =>
73+
let getOr = (opt, default) =>
7474
switch opt {
7575
| Some(x) => x
7676
| None => default

src/Core__Option.resi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,19 @@ Option.getUnsafe(None) // Raises an error
9696
external getUnsafe: option<'a> => 'a = "%identity"
9797

9898
/**
99-
`mapWithDefault(opt, default, f)` returns `f(value)` if `opt` is `Some(value)`, otherwise `default`.
99+
`mapOr(opt, default, f)` returns `f(value)` if `opt` is `Some(value)`, otherwise `default`.
100100
101101
## Examples
102102
103103
```rescript
104104
let someValue = Some(3)
105-
someValue->Option.mapWithDefault(0, x => x + 5) // 8
105+
someValue->Option.mapOr(0, x => x + 5) // 8
106106
107107
let noneValue = None
108-
noneValue->Option.mapWithDefault(0, x => x + 5) // 0
108+
noneValue->Option.mapOr(0, x => x + 5) // 0
109109
```
110110
*/
111-
let mapWithDefault: (option<'a>, 'b, 'a => 'b) => 'b
111+
let mapOr: (option<'a>, 'b, 'a => 'b) => 'b
112112

113113
/**
114114
`map(opt, f)` returns `Some(f(value))` if `opt` is `Some(value)`, otherwise `None`.
@@ -143,22 +143,22 @@ Option.flatMap(None, addIfAboveOne) // None
143143
let flatMap: (option<'a>, 'a => option<'b>) => option<'b>
144144

145145
/**
146-
`getWithDefault(opt, default)` returns `value` if `opt` is `Some(value)`, otherwise `default`.
146+
`getOr(opt, default)` returns `value` if `opt` is `Some(value)`, otherwise `default`.
147147
148148
## Examples
149149
150150
```rescript
151-
Option.getWithDefault(None, "Banana") // Banana
152-
Option.getWithDefault(Some("Apple"), "Banana") // Apple
151+
Option.getOr(None, "Banana") // Banana
152+
Option.getOr(Some("Apple"), "Banana") // Apple
153153
154154
let greet = (firstName: option<string>) =>
155-
"Greetings " ++ firstName->Option.getWithDefault("Anonymous")
155+
"Greetings " ++ firstName->Option.getOr("Anonymous")
156156
157157
Some("Jane")->greet // "Greetings Jane"
158158
None->greet // "Greetings Anonymous"
159159
```
160160
*/
161-
let getWithDefault: (option<'a>, 'a) => 'a
161+
let getOr: (option<'a>, 'a) => 'a
162162

163163
/**
164164
`orElse(opt1, opt2)` returns `opt2` if `opt1` is `None`, otherwise `opt1`.

src/Core__Result.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function getExn(x) {
1212
};
1313
}
1414

15-
function mapWithDefault(opt, $$default, f) {
15+
function mapOr(opt, $$default, f) {
1616
var f$1 = Curry.__1(f);
1717
if (opt.TAG === /* Ok */0) {
1818
return f$1(opt._0);
@@ -48,7 +48,7 @@ function flatMap(opt, f) {
4848
}
4949
}
5050

51-
function getWithDefault(opt, $$default) {
51+
function getOr(opt, $$default) {
5252
if (opt.TAG === /* Ok */0) {
5353
return opt._0;
5454
} else {
@@ -104,10 +104,10 @@ function cmp(a, b, f) {
104104

105105
export {
106106
getExn ,
107-
mapWithDefault ,
107+
mapOr ,
108108
map ,
109109
flatMap ,
110-
getWithDefault ,
110+
getOr ,
111111
isOk ,
112112
isError ,
113113
eq ,

0 commit comments

Comments
 (0)