Consider the following: (Note: I modified the output slightly for readability)
~> @(11..20)
11, 12, 13, 14, 15, 16, 17, 18, 19, 20
~> @(11..20+1)
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 1
~> @(1+11..20)
InvalidOperation: Method invocation failed because [System.Object[]] does not contain a method named 'op_Addition'.
I've always found this array addition syntax to be confusing, and would much prefer something like @(1,11..20).
At any rate, why does the 3rd operation not work identically to the 2nd?
Is it because 1 is not considered an array, even though it is being given as part of the array definition syntax?
~> @(1,2+11..20)
1, 2, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
If that's the case then why does @(11..20+1) work as expected?
I can work around this in a few ways...
~> @(@(1)+11..20)
1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
~> @(,1+11..20)
1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
~> @(11..20+1) | Sort
1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
But those seem pretty ugly, inelegant, and the latter workaround doesn't account for instances where I don't actually want to sort the array.
The one that makes the most sense is @(,1+11..20), though it's not particularly pleasing. Is there a more proper way to achieve the desired result in the desired order, without the additional syntax or piping?
None of the examples in the official documentation demonstrate this particular permutation.
Thanks.
@( ).