Standard Library: Now open for improvements and suggestions!

regarding the List → Vector switch (Make Vector The Default Implementation), the Core Team decision was: Core Team Meeting Notes - #12 by tgodzik

Yes, it would be great to have non-empty collectionsw

can the whole STD library be revised for enforcing explicit nulls everywhere?, including iterators and so on, this may be breaking but also one of the few appropriate moments

1 Like

I would also like Array and IArray to be destructured using :+ and +: in match statements.

boundary/break and Try as it is currently don’t play well with each other:

for the Seq() List → Vector switch, atleast we can use getenv or System.getProperty to opt-in to the new default, can’t we?

why would you want to do this if it could only be implemented by copying the tail every time? i guess this is not for a loop algorithm?

For ergonomics on small arrays. And orthogonality, because such match works on all other collections.

I have recently migrated Vectors to IArrays, this is how I encountered this quirk. Most of them are less than 20 elements, commonly much less. And :+ is cheaper on IArray than Vector for (my estimate) collections under 100 elements. System.arrayCopy is much more efficient than shuffling pointers around for Vector.

By the same argument, :+ (popping off last element) on List should not be supported, because it is prohibitively expensive, even more than on Array.

2 Likes

Ah, I also propose an optimization to extractors.

I think that a match like case beginning :+ a :+ b :+ c makes three linear copies of ArraySeq / Vector, which is contrary to expectation. Ideally it would just pick out last three elements and do one dropRight(3).

Or (or in addition to), we could support matches where the glob is not necessarily at the end, such as case ArraySeq(beginning*, a, b, c)

I know this is probably not necessarily a library thing but a more involved redesign, but just putting it here because we have just talked about a related topic.

2 Likes

Look guys, you’re not going to get your feature into the standard library by posting comments on this thread. If you want to make that happen, follow the process and make a thread for whatever it is that you’re proposing and collect feedback. Other people aren’t going to do that for you.

1 Like

Not sure if this was suggested before. Would be nice to use named tuples in return types in collections, for example:

partition -> (passed: CC, rejected: CC)
partitionMap -> (lefts: CC, rights: CC)
span -> (takeWhile: CC, dropWhile: CC)
splitAt -> (taken: CC, dropped: CC)

This would make it easier to think about returned values, no need to look up which value in tuple is lefts/rights etc.


Also would be nice in Maps:

map.map: entry =>
  println(entry.key)
  println(entry.value)

EDIT: Seb said it breaks TASTY, so no cookie. :smiling_face_with_tear:

7 Likes

Start a thread with SLC: prefix, see Scala Standard Library Process | The Scala Programming Language

1 Like