scala.util

package scala.util

Members list

Packages

Type members

Classlikes

A utility object to support command line parsing for @main methods

A utility object to support command line parsing for @main methods

Attributes

Source
CommandLineParser.scala
Supertypes
class Object
trait Matchable
class Any
Self type
trait FromDigits[T]

A type class for types that admit numeric literals.

A type class for types that admit numeric literals.

Attributes

Companion
object
Source
FromDigits.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait Decimal[T]
trait Floating[T]
trait WithRadix[T]
object FromDigits

Attributes

Companion
trait
Source
FromDigits.scala
Supertypes
class Object
trait Matchable
class Any
Self type
FromDigits.type

Attributes

Source
NotGiven.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object NotGiven
final class NotGiven[+T]

A special class used to implement negation in implicit search.

A special class used to implement negation in implicit search.

Consider the problem of using implicit i1 for a query type D if an implicit for some other class C is available, and using an implicit i2 if no implicit value of type C is available. If we do not want to prioritize i1 and i2 by putting them in different traits we can instead define the following:

given i1: D(using ev: C) = ... given i2: D(using ev: NotGiven[C]) = ...

NotGiven is treated specially in implicit search, similar to the way logical negation is treated in Prolog: The implicit search for NotGiven[C] succeeds if and only if the implicit search for C fails.

In Scala 2 this form of negation can be simulated by setting up a conditional ambiguous implicit and an unconditional fallback, the way it is done with the default, amb1 and amb2 methods below. Due to the way these two methods are defined, NotGiven is also usable from Scala 2.

In Dotty, ambiguity is a global error, and therefore cannot be used to implement negation. Instead, NotGiven is treated natively in implicit search.

Attributes

Companion
object
Source
NotGiven.scala
Supertypes
class Object
trait Matchable
class Any
object NotGiven extends LowPriorityNotGiven

Attributes

Companion
class
Source
NotGiven.scala
Supertypes
class Object
trait Matchable
class Any
Self type
NotGiven.type
object boundary

A boundary that can be exited by break calls. boundary and break represent a unified and superior alternative for the scala.util.control.NonLocalReturns and scala.util.control.Breaks APIs. The main differences are:

A boundary that can be exited by break calls. boundary and break represent a unified and superior alternative for the scala.util.control.NonLocalReturns and scala.util.control.Breaks APIs. The main differences are:

  • Unified names: boundary to establish a scope, break to leave it. break can optionally return a value.
  • Integration with exceptions. breaks are logically non-fatal exceptions. The Break exception class extends RuntimeException and is optimized so that stack trace generation is suppressed.
  • Better performance: breaks to enclosing scopes in the same method can be rewritten to jumps.

Example usage:

import scala.util.boundary, boundary.break

def firstIndex[T](xs: List[T], elem: T): Int =
  boundary:
    for (x, i) <- xs.zipWithIndex do
      if x == elem then break(i)
    -1

Attributes

Source
boundary.scala
Supertypes
class Object
trait Matchable
class Any
Self type
boundary.type

Experimental classlikes

sealed trait TupledFunction[F, G]

Type class relating a FunctionN[..., R] with an equivalent tupled function Function1[TupleN[...], R]

Type class relating a FunctionN[..., R] with an equivalent tupled function Function1[TupleN[...], R]

Type parameters

F

a function type

G

a tupled function type (function of arity 1 receiving a tuple as argument)

Attributes

Experimental
true
Source
TupledFunction.scala
Supertypes
class Object
trait Matchable
class Any