Skip to content

Proposal: Structure of extension methods #46

Open
@BalmungSan

Description

@BalmungSan

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:

  1. 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.
  2. 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).
  3. 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 a next 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 into Next<Name>Extensions MUST be declared in the package object next; and MUST be named scalaNextSyntaxFor<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:

  1. One single next package for all extensions: scala.next._
  2. 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. (👎)

Metadata

Metadata

Assignees

No one assigned

    Labels

    metameta-discussions about the nature and scope of this repo

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions