Open
Description
This proposal is based upon #24 for naming and package structure (here we are assuming that both proposals were chosen, at least partially) and further specifies where should the extension methods be placed.
This proposal has three end goals:
- Provide users with an easy way to access the extended functionality; which leaves the door open for cross-compiling with
3.1
in the future. - Ensure names that will not be part of a future Scala release to be on a
next
subpackage (as required by Proposals for naming and package structure #24). - Strive for a codebase that is easy to maintain.
As such, I propose the following:
- All extension methods for the same type MUST be defined in a single class named
Next<Name>Extensions
placed in anext
subpackage. - Such class MUST be
final
&private[next]
- Such class MUST be a value class; and its single constructor argument MUST be
private
. - Such class MUST be placed in a file called
Next<Name>Extensions.scala
. - Such file MUST only contain the previous defined class.
- Such file must exist inside a
next
subdirectory. - Finally, the implicit conversion from
Name
intoNext<Name>Extensions
MUST be declared in the package objectnext
; and MUST be namedscalaNextSyntaxFor<Name>
.
Example:
// file: src/main/scala/scala/next/Next<Name>Extensions.scala
package scala.next
private[next] final class Next<Name>Extensions[A](private val col: <Name>[A]) extends AnyVal {
// Extension methods go here.
}
// file: src/main/scala/scala/next/package.scala
package scala
import scala.language.implicitConversions
package object next {
implicit final def scalaNextSyntaxFor<Name>[A](coll: <Name>[A]): Next<Name>Extensions[A] =
new Next<Name>Extensions(col)
}
One open discussion for this proposal would be:
- One single
next
package for all extensions:scala.next._
- Multiple
next
packages for each package of the stdlib:scala.collection.next._
,scala.collection.immutable.next._
, etc.
Vote with:
In favour of this proposal going with option 1. (👍)
In favour of this proposal going with option 2. (🚀)
Completely against this proposal. (👎)