-
Notifications
You must be signed in to change notification settings - Fork 38
Spread anywhere feature #692
Changes from 5 commits
0447df1
3f77897
769d719
b34ec30
3459747
cefe805
4733641
72409f1
362fca5
f14b41e
9a81c95
00226bf
ecc4d40
001501f
0e005c0
61ac172
e71a61a
839d3e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,20 +49,6 @@ Explanation: you can't collect a subset of a record's field into its own record, | |
Solution: you need to pull out each field you want explicitly. | ||
|
||
|
||
Syntax error! | ||
tests/parsing/errors/other/spread.res:8:1-3 | ||
|
||
6 │ | ||
7 │ let myList = list{...x, ...y} | ||
8 │ let list{...x, ...y} = myList | ||
9 │ | ||
10 │ type t = {...a} | ||
|
||
Lists can only have one `...` spread, and at the end. | ||
Explanation: lists are singly-linked list, where a node contains a value and points to the next node. `list{a, ...bc}` efficiently creates a new item and links `bc` as its next nodes. `list{...bc, a}` would be expensive, as it'd need to traverse `bc` and prepend each item to `a` one by one. We therefore disallow such syntax sugar. | ||
Solution: directly use `concat`. | ||
|
||
|
||
Syntax error! | ||
tests/parsing/errors/other/spread.res:8:13-22 | ||
|
||
|
@@ -114,7 +100,7 @@ let arr = [|x;y|] | |
let [|arr;_|] = [|1;2;3|] | ||
let record = { x with y } | ||
let { x; y } = myRecord | ||
let myList = x :: y | ||
let myList = Belt.List.concatMany [|x;y|] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let x::y = myList | ||
type nonrec t = < a > | ||
type nonrec t = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ let x = list{} | |
let x = list{1} | ||
let x = list{1, 2} | ||
let x = list{1, 2, 3} | ||
let x = Belt.List.concatMany([list{1, 2, ...x}, list{3, ...x}]) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this be improved? print it as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be, but just by changing the printer can cause some problems. For example, list{. . x, . .y} and Belt.List.concatMany([x, y]) will be printed as the same thing. I am still trying to solve this problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add an attribute to Belt.List.concatMany to avoid accidental simplifications? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what is done for string templates, I believe, to differentiate from normal string concatenation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for all your suggestions, I'll learn more about that. |
||
let x = list{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add some more test cases, some edge cases like: let x = list{ ...xs}
let x = list{1, ...xs}
let x = list{xs, ... ys}
let x = list{ ...xs, ... ys} |
||
superLoooooooooooooooooooooooooooooongIiiiiiiiiideeeentifieeeeeeeeeeeeeeeeer, | ||
|
@@ -17,3 +18,15 @@ let x = list{ | |
superLoooooooooooooooooooooooooooooongIiiiiiiiiideeeentifieeeeeeeeeeeeeeeeer, | ||
...superLoooooooooooooooooooooooooooooongListHere, | ||
} | ||
|
||
let x = Belt.List.concatMany([ | ||
list{ | ||
superLoooooooooooooooooooooooooooooongIiiiiiiiiideeeentifieeeeeeeeeeeeeeeeer, | ||
superLoooooooooooooooooooooooooooooongIiiiiiiiiideeeentifieeeeeeeeeeeeeeeeer, | ||
...superLoooooooooooooooooooooooooooooongListHere, | ||
}, | ||
list{ | ||
superLoooooooooooooooooooooooooooooongIiiiiiiiiideeeentifieeeeeeeeeeeeeeeeer, | ||
...superLoooooooooooooooooooooooooooooongListHere, | ||
}, | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of comment unused code, can you just remove it