# Naming conventions for collections API

**URL:** <https://contributors.scala-lang.org/t/naming-conventions-for-collections-api/4592>\
**Category:** Scala Platform\
**Created:** [October 28, 2020, 6:18pm UTC](https://contributors.scala-lang.org/t/naming-conventions-for-collections-api/4592 "2020-10-28T18:18:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![liontiger23](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/liontiger23/32/1664_2.png) [@liontiger23](https://contributors.scala-lang.org/u/liontiger23)\
**Post date:** [October 28, 2020, 6:18pm UTC](https://contributors.scala-lang.org/t/naming-conventions-for-collections-api/4592/1 "2020-10-28T18:18:27Z")

</div>

Recently I’ve noticed that collections API names in Scala are a bit inconsistent: there are methods with `-ed` like `sorted`, `appended` and `prepended`, but also the ones without `-ed` like `reverse`, `filter`, `map` and more bizarrely `sortWith` and `sortBy` (not `sortedWith` and `sortedBy`).  
In a similar vein we also have `filterInPlace`, `mapInPlace` and `sortInPlace`.  
So it seems that the verbs are preferred rather than adjectives with `-ed`.

However, I couldn’t find any definitive guidelines on this naming preference and on what naming scheme to use in my own collections for similar methods and in general.

So I was wondering what are the rules for choosing `-ed` vs. no `-ed`?  
Or perhaps `sorted` was just unfortunately named at the time, and will at some point be replaced by `sort`?

---

<div class="post-metadata">

**Author:** ![som-snytt](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/som-snytt/32/595_2.png) [@som-snytt](https://contributors.scala-lang.org/u/som-snytt)\
**Post date:** [October 28, 2020, 9:55pm UTC](https://contributors.scala-lang.org/t/naming-conventions-for-collections-api/4592/2 "2020-10-28T21:55:49Z")

</div>

A quick answer is that `-ed` means a new collection is produced (possibly with structural sharing).

But many traditional names are traditionally functional and operate on immutable data, such as `map`.

So the mutable version is `InPlace`.

Prepend to something mutable is `prepend`, prepend to something immutable is `prepended`.

My sense is that they paid attention to the naming issue and they will never offer the ambiguous `sort`. I’m only comfortable with API I use frequently. Thank goodness for `map` and `filter` and `flatMap`.

Here is one commit for `prepended`: [https://github.com/scala/scala/commit/1fc1a4de604e9e616f4c9c6aad75ca4138d8793a](https://github.com/scala/scala/commit/1fc1a4de604e9e616f4c9c6aad75ca4138d8793a)

It looks like you hit a blame wall because the work was done in a separate repository, so archaeology would require extra digging.

Autocomplete on `ListBuffer` asks if I want to see 220 completions; `List` is only 184. So maybe it’s a way to get me to use immutable data structures.

---

<div class="post-metadata">

**Author:** ![SethTisue](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/sethtisue/32/3185_2.png) [@SethTisue](https://contributors.scala-lang.org/u/SethTisue)\
**Post date:** [November 17, 2020, 12:02am UTC](https://contributors.scala-lang.org/t/naming-conventions-for-collections-api/4592/3 "2020-11-17T00:02:09Z")

</div>

@julienrf do you recall if there is any kind of documentation or on-the-record discussion about this?

---

<div class="post-metadata">

**Author:** ![julienrf](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/julienrf/32/4_2.png) [@julienrf](https://contributors.scala-lang.org/u/julienrf)\
**Post date:** [November 17, 2020, 7:31am UTC](https://contributors.scala-lang.org/t/naming-conventions-for-collections-api/4592/4 "2020-11-17T07:31:41Z")

</div>

No, I don’t know, `sorted`, `sortWith`, and `sortBy` were already there in 2.10 (and maybe even before that) 🙂

I agree that the naming scheme is not consistent…
