Closed stepancheg closed 11 years ago
Another approach that wouldn't need a new function would be to use the keyword syntax, as in Vector[Int](elements:[1,2,3])
.
@jckarter if it's OK to pass elements in a tuple, we don't need a keyword:
Vector[Int]([1, 2, 3])
Before this commit
Vector
functions were over-overloaded: call tocould interpret
a
as a sequence or as an element parameter. This is over-overloading that make code harder to read and maintain.This commit changes sequence construction API. New convention is proposed:
Let
Foo
be sequence type.Calls
assume arg is a sequence. Call
interpret args as elements for new foo sequence. Latter call does not work when args list is empty (because type parameter for
Foo
cannot be infered and thus must be specified).To deal with this problem,
elements
function is proposed:elements
function with non-empty parameters list returns an array of arguments, andelements
with empty args returns special sequence-like record NoElements, that has no type parameter (thuselements()
call does not fail, unlikevector()
).This patch changes vector, vectorQueue and deque.
Alternative version
Alternative version of this pull request: #483, that uses tuples for parameters instead of
elements
function.