fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
345 stars 21 forks source link

Mixing ranges and values to construct sequences #1031

Open Happypig375 opened 3 years ago

Happypig375 commented 3 years ago

Mixing ranges and values to construct sequences

I propose we allow:

let a = seq { 1..10; 19 }
let b = [-3; 1..10]
let c = [|-3; 1..10; 19|]

The existing way of approaching this problem in F# is

let a = seq { yield! seq { 1..10 }; 19 }
let b = [-3; yield! [1..10]]
let c = [|-3; yield! [|1..10|]; 19|]

It's annoying to have to insert a whole yield! just to add a range.

Pros and Cons

The advantages of making this adjustment to F# are

  1. Conciseness
  2. Convenience
  3. Possibility of optimisation

The disadvantage of making this adjustment to F# is none.

Extra information

Estimated cost (XS, S, M, L, XL, XXL): S

Related suggestions: (none)

Affidavit (please submit!)

Please tick this by placing a cross in the box:

Please tick all that apply:

For Readers

If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.

Swoorup commented 3 years ago

Seems like a reasonable request to me. Currently, the range syntax for list is

let a = [1..10]

Doesn't seem like much harm, to expand it to be able to include multiple ranges or single value like

let a = [-100; 1..10; 100-120]
dsyme commented 3 years ago

Yes this is pretty reasonable, especially now yield is essentially optional

I'll mark it as approved in principle. I'd be interested to know if any problems came from a prototype.

dsyme commented 2 years ago

Marking this as approved in principle