Skip to content

Commit d1c9aef

Browse files
authored
Clean list API (#7290)
* remove List.t<'a> from Core and use list<'a> instead * rename `toShuffled` to `shuffle` and deprecate it * deprecate List.*Assoc functions towards the use of Map * update changelog * fix typo in fromInitializer docstring * fix typo in docstring * fix completion tests
1 parent 80744a5 commit d1c9aef

File tree

9 files changed

+104
-76
lines changed

9 files changed

+104
-76
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 12.0.0-alpha.9 (Unreleased)
1414

15+
#### :boom: Breaking Change
16+
17+
- Clean list API. https://github.com/rescript-lang/rescript/pull/7290
18+
1519
#### :nail_care: Polish
1620

1721
- Allow single newline in JSX. https://github.com/rescript-lang/rescript/pull/7269

lib/es6/Stdlib_List.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ function toArray(x) {
646646
return arr;
647647
}
648648

649-
function toShuffled(xs) {
649+
function shuffle(xs) {
650650
let v = toArray(xs);
651651
Stdlib_Array.shuffle(v);
652652
return fromArray(v);
@@ -1298,6 +1298,8 @@ function zip(l1, l2) {
12981298

12991299
let size = length;
13001300

1301+
let toShuffled = shuffle;
1302+
13011303
export {
13021304
length,
13031305
size,
@@ -1310,6 +1312,7 @@ export {
13101312
getExn,
13111313
make,
13121314
fromInitializer,
1315+
shuffle,
13131316
toShuffled,
13141317
drop,
13151318
take,

lib/js/Stdlib_List.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ function toArray(x) {
646646
return arr;
647647
}
648648

649-
function toShuffled(xs) {
649+
function shuffle(xs) {
650650
let v = toArray(xs);
651651
Stdlib_Array.shuffle(v);
652652
return fromArray(v);
@@ -1298,6 +1298,8 @@ function zip(l1, l2) {
12981298

12991299
let size = length;
13001300

1301+
let toShuffled = shuffle;
1302+
13011303
exports.length = length;
13021304
exports.size = size;
13031305
exports.head = head;
@@ -1309,6 +1311,7 @@ exports.get = get;
13091311
exports.getExn = getExn;
13101312
exports.make = make;
13111313
exports.fromInitializer = fromInitializer;
1314+
exports.shuffle = shuffle;
13121315
exports.toShuffled = toShuffled;
13131316
exports.drop = drop;
13141317
exports.take = take;

runtime/Stdlib_List.res

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@
6161

6262
@@config({flags: ["-bs-noassertfalse"]})
6363

64-
type t<'a> = list<'a>
65-
6664
module A = {
6765
@new external makeUninitializedUnsafe: int => array<'a> = "Array"
6866
external min: ('a, 'a) => 'a = "%bs_min"
@@ -85,7 +83,7 @@ module A = {
8583
}
8684
}
8785

88-
external mutableCell: ('a, t<'a>) => t<'a> = "#makemutablelist"
86+
external mutableCell: ('a, list<'a>) => list<'a> = "#makemutablelist"
8987

9088
/*
9189
`mutableCell x []` == `x`
@@ -94,7 +92,7 @@ external mutableCell: ('a, t<'a>) => t<'a> = "#makemutablelist"
9492
dont inline a binding to mutable cell, it is mutable
9593
*/
9694
/* INVARIANT: relies on Literals.tl (internal representation) */
97-
@set external unsafeMutateTail: (t<'a>, t<'a>) => unit = "tl"
95+
@set external unsafeMutateTail: (list<'a>, list<'a>) => unit = "tl"
9896

9997
/*
10098
- the cell is not empty
@@ -480,19 +478,22 @@ let rec fromArrayAux = (a, i, res) =>
480478

481479
let fromArray = a => fromArrayAux(a, Stdlib_Array.length(a) - 1, list{})
482480

483-
let toArray = (x: t<_>) => {
481+
let toArray = (x: list<_>) => {
484482
let len = length(x)
485483
let arr = A.makeUninitializedUnsafe(len)
486484
fillAux(arr, 0, x)
487485
arr
488486
}
489487

490-
let toShuffled = xs => {
488+
let shuffle = xs => {
491489
let v = toArray(xs)
492490
Stdlib_Array.shuffle(v)
493491
fromArray(v)
494492
}
495493

494+
@deprecated("Use `shuffle` instead")
495+
let toShuffled = shuffle
496+
496497
let rec reverseConcat = (l1, l2) =>
497498
switch l1 {
498499
| list{} => l2
@@ -688,6 +689,7 @@ let rec has = (xs, x, eq) =>
688689
| list{a, ...l} => eq(a, x) || has(l, x, eq)
689690
}
690691

692+
@deprecated("Use a `Map` instead")
691693
let rec getAssoc = (xs, x, eq) =>
692694
switch xs {
693695
| list{} => None
@@ -699,12 +701,14 @@ let rec getAssoc = (xs, x, eq) =>
699701
}
700702
}
701703

704+
@deprecated("Use a `Map` instead")
702705
let rec hasAssoc = (xs, x, eq) =>
703706
switch xs {
704707
| list{} => false
705708
| list{(a, _), ...l} => eq(a, x) || hasAssoc(l, x, eq)
706709
}
707710

711+
@deprecated("Use a `Map` instead")
708712
let removeAssoc = (xs, x, eq) =>
709713
switch xs {
710714
| list{} => list{}
@@ -722,6 +726,7 @@ let removeAssoc = (xs, x, eq) =>
722726
}
723727
}
724728

729+
@deprecated("Use a `Map` instead")
725730
let setAssoc = (xs, x, k, eq) =>
726731
switch xs {
727732
| list{} => list{(x, k)}

0 commit comments

Comments
 (0)