Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7ba68b8

Browse files
committedJul 18, 2023
Array.fromSingleton
1 parent 7cae2f8 commit 7ba68b8

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
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 fromOneItem: 'a => array<'a> = "Array.of"
249+
@val external fromSingleton: 'a => array<'a> = "Array.of"

‎src/Core__Array.resi

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

973973
/**
974-
`fromOneItem` 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)
974+
`fromSingleton` generates a new array from a single value.
975975

976976
## Examples
977977

978978
```rescript
979-
3->Array.fromOneItem // [3]
980-
undefined->Array.fromOneItem // [undefined]
981-
Some("abc")->Array.fromOneItem // [Some("abc")]
982-
[1,2,3]->Array.fromOneItem // [[1,2,3]]
983-
{"x": 3, "y": 5}->Array.fromOneItem // Some({"x": 3, "y": 5})
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})
984983
```
984+
985+
## Specifications
986+
987+
- [Array.of MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of)
988+
- [Array.of ECMAScript Language Specification](https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.of)
985989
*/
986990
@val
987-
external fromOneItem: 'a => array<'a> = "Array.of"
991+
external fromSingleton: 'a => array<'a> = "Array.of"

‎test/ArrayTests.mjs

+6-6
Original file line numberDiff line numberDiff line change
@@ -407,27 +407,27 @@ function singletonTest(a, title) {
407407
"ArrayTests.res",
408408
103,
409409
22,
410-
46
410+
48
411411
],
412-
"fromOneItem : " + title + ""
412+
"fromSingleton : " + title + ""
413413
], Array.of(a), Caml_obj.equal, [a]);
414414
Test.run([
415415
[
416416
"ArrayTests.res",
417417
104,
418418
22,
419-
46
419+
48
420420
],
421-
"fromOneItem : " + title + ""
421+
"fromSingleton : " + title + ""
422422
], Array.of(a).length, eq, 1);
423423
Test.run([
424424
[
425425
"ArrayTests.res",
426426
106,
427427
15,
428-
39
428+
41
429429
],
430-
"fromOneItem : " + title + ""
430+
"fromSingleton : " + title + ""
431431
], Array.of(a)[0], (function (i, j) {
432432
return i === j;
433433
}), a);

‎test/ArrayTests.res

+5-5
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ Test.run(
100100
)
101101

102102
let singletonTest = (a, title) => {
103-
Test.run(__POS_OF__(`fromOneItem : ${title}`), Array.fromOneItem(a), (i, j) => i == j, [a])
104-
Test.run(__POS_OF__(`fromOneItem : ${title}`), Array.fromOneItem(a)->Array.length, eq, 1)
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)
105105
Test.run(
106-
__POS_OF__(`fromOneItem : ${title}`),
107-
Array.fromOneItem(a)->Array.getUnsafe(0),
106+
__POS_OF__(`fromSingleton : ${title}`),
107+
Array.fromSingleton(a)->Array.getUnsafe(0),
108108
(i, j) => i === j,
109109
a,
110110
)
111111
}
112-
let m = {"x": 3, "y": 5}->Array.fromOneItem
112+
let m = {"x": 3, "y": 5}->Array.fromSingleton
113113
3->singletonTest("Single integer")
114114
"abc"->singletonTest("Single string")
115115
undefined->singletonTest("undefined")

0 commit comments

Comments
 (0)
Please sign in to comment.