Skip to content

Commit c271c9a

Browse files
committed
rename to "of1" similar to Javascript name
1 parent 7ba68b8 commit c271c9a

File tree

5 files changed

+41
-45
lines changed

5 files changed

+41
-45
lines changed

src/Core__Array.res

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,4 @@ let findMap = (arr, f) => {
246246

247247
@send external at: (array<'a>, int) => option<'a> = "at"
248248

249-
@val external fromSingleton: 'a => array<'a> = "Array.of"
249+
@val external of1: 'a => array<'a> = "Array.of"

src/Core__Array.resi

+7-6
Original file line numberDiff line numberDiff line change
@@ -971,15 +971,16 @@ let findMap: (array<'a>, 'a => option<'b>) => option<'b>
971971
external at: (array<'a>, int) => option<'a> = "at"
972972

973973
/**
974-
`fromSingleton` generates a new array from a single value.
974+
`of1` generates a new array from a single value. See [Array.of on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
975975

976976
## Examples
977977

978978
```rescript
979-
3->Array.fromSingleton // [3]
980-
undefined->Array.fromSingleton // [undefined]
981-
Some("abc")->Array.fromSingleton // [Some("abc")]
982-
{"x": 3, "y": 5}->Array.fromSingleton // Some({"x": 3, "y": 5})
979+
3->Array.of1 // [3]
980+
undefined->Array.of1 // [undefined]
981+
Some("abc")->Array.of1 // [Some("abc")]
982+
[1,2,3]->Array.of1 // [[1,2,3]]
983+
{"x": 3, "y": 5}->Array.of1 // Some({"x": 3, "y": 5})
983984
```
984985

985986
## Specifications
@@ -988,4 +989,4 @@ Some("abc")->Array.fromSingleton // [Some("abc")]
988989
- [Array.of ECMAScript Language Specification](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.of)
989990
*/
990991
@val
991-
external fromSingleton: 'a => array<'a> = "Array.of"
992+
external of1: 'a => array<'a> = "Array.of"

test/ArrayTests.mjs

+18-18
Original file line numberDiff line numberDiff line change
@@ -401,33 +401,33 @@ Test.run([
401401

402402
})), eq, undefined);
403403

404-
function singletonTest(a, title) {
404+
function of1Test(a, title) {
405405
Test.run([
406406
[
407407
"ArrayTests.res",
408408
103,
409409
22,
410-
48
410+
38
411411
],
412-
"fromSingleton : " + title + ""
412+
"of1 : " + title + ""
413413
], Array.of(a), Caml_obj.equal, [a]);
414414
Test.run([
415415
[
416416
"ArrayTests.res",
417417
104,
418418
22,
419-
48
419+
38
420420
],
421-
"fromSingleton : " + title + ""
421+
"of1 : " + title + ""
422422
], Array.of(a).length, eq, 1);
423423
Test.run([
424424
[
425425
"ArrayTests.res",
426-
106,
427-
15,
428-
41
426+
105,
427+
22,
428+
38
429429
],
430-
"fromSingleton : " + title + ""
430+
"of1 : " + title + ""
431431
], Array.of(a)[0], (function (i, j) {
432432
return i === j;
433433
}), a);
@@ -438,29 +438,29 @@ var m = Array.of({
438438
y: 5
439439
});
440440

441-
singletonTest(3, "Single integer");
441+
of1Test(3, "Single integer");
442442

443-
singletonTest("abc", "Single string");
443+
of1Test("abc", "Single string");
444444

445-
singletonTest(undefined, "undefined");
445+
of1Test(undefined, "undefined");
446446

447-
singletonTest(null, "null");
447+
of1Test(null, "null");
448448

449-
singletonTest([
449+
of1Test([
450450
1,
451451
2,
452452
3
453453
], "full array of integers");
454454

455-
singletonTest([], "empty array");
455+
of1Test([], "empty array");
456456

457-
singletonTest(5, "Some");
457+
of1Test(5, "Some");
458458

459-
singletonTest(undefined, "None");
459+
of1Test(undefined, "None");
460460

461461
export {
462462
eq ,
463-
singletonTest ,
463+
of1Test ,
464464
m ,
465465
}
466466
/* Not a pure module */

test/ArrayTests.res

+13-18
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,17 @@ Test.run(
9999
None,
100100
)
101101

102-
let singletonTest = (a, title) => {
103-
Test.run(__POS_OF__(`fromSingleton : ${title}`), Array.fromSingleton(a), (i, j) => i == j, [a])
104-
Test.run(__POS_OF__(`fromSingleton : ${title}`), Array.fromSingleton(a)->Array.length, eq, 1)
105-
Test.run(
106-
__POS_OF__(`fromSingleton : ${title}`),
107-
Array.fromSingleton(a)->Array.getUnsafe(0),
108-
(i, j) => i === j,
109-
a,
110-
)
102+
let of1Test = (a, title) => {
103+
Test.run(__POS_OF__(`of1 : ${title}`), Array.of1(a), (i, j) => i == j, [a])
104+
Test.run(__POS_OF__(`of1 : ${title}`), Array.of1(a)->Array.length, eq, 1)
105+
Test.run(__POS_OF__(`of1 : ${title}`), Array.of1(a)->Array.getUnsafe(0), (i, j) => i === j, a)
111106
}
112-
let m = {"x": 3, "y": 5}->Array.fromSingleton
113-
3->singletonTest("Single integer")
114-
"abc"->singletonTest("Single string")
115-
undefined->singletonTest("undefined")
116-
null->singletonTest("null")
117-
[1, 2, 3]->singletonTest("full array of integers")
118-
[]->singletonTest("empty array")
119-
Some(5)->singletonTest("Some")
120-
None->singletonTest("None")
107+
let m = {"x": 3, "y": 5}->Array.of1
108+
3->of1Test("Single integer")
109+
"abc"->of1Test("Single string")
110+
undefined->of1Test("undefined")
111+
null->of1Test("null")
112+
[1, 2, 3]->of1Test("full array of integers")
113+
[]->of1Test("empty array")
114+
Some(5)->of1Test("Some")
115+
None->of1Test("None")

test/TestSuite.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var Concurrently = PromiseTest.Concurrently;
2828

2929
var panicTest = ErrorTests.panicTest;
3030

31-
var singletonTest = ArrayTests.singletonTest;
31+
var of1Test = ArrayTests.of1Test;
3232

3333
var m = ArrayTests.m;
3434

@@ -65,7 +65,7 @@ export {
6565
Catching ,
6666
Concurrently ,
6767
panicTest ,
68-
singletonTest ,
68+
of1Test ,
6969
m ,
7070
$$catch ,
7171
forEachIfOkCallFunction ,

0 commit comments

Comments
 (0)