com.mchange.conveniences.collection.core.scala~ Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of conveniences_3 Show documentation
Show all versions of conveniences_3 Show documentation
Conveniences, usually extension methods, that seem useful across projects.
The newest version!
package com.mchange.conveniences.collection
import scala.collection.*
object NotUnique:
case object Empty extends NotUnique
case class Multiple( n : Int ) extends NotUnique
sealed trait NotUnique
extension[T] ( c : Seq[T] | Set[T] )
def uniqueOr( notUnique : NotUnique => T ) : T =
c.size match
case 0 => notUnique( NotUnique.Empty )
case 1 => c.head
case n => notUnique( NotUnique.Multiple(n) )