Conversion

@FunctionalInterface
abstract class Conversion[-T, +U] extends T => U

A class for implicit values that can serve as implicit conversions The implicit resolution algorithm will act as if there existed the additional implicit definition:

def $implicitConversion[T, U](x: T)(c: Conversion[T, U]): U = c(x)

However, the presence of this definition would slow down implicit search since its outermost type matches any pair of types. Therefore, implicit search contains a special case in Implicits#discardForView which emulates the conversion in a more efficient way.

Note that this is a SAM class - function literals are automatically converted to the Conversion values.

Also note that in bootstrapped dotty, Predef.<:< should inherit from Conversion. This would cut the number of special cases in discardForView from two to one.

The Conversion class can also be used to convert explicitly, using the convert extension method.

Source:
Conversion.scala
trait T => U
class Object
trait Matchable
class Any

Value members

Abstract methods

def apply(x: T): U

Convert value x of type T to type U

Convert value x of type T to type U

Source:
Conversion.scala

Inherited methods

def andThen[A](g: U => A): T => A

Composes two instances of Function1 in a new Function1, with this function applied first.

Composes two instances of Function1 in a new Function1, with this function applied first.

Type parameters:
A

the result type of function g

Value parameters:
g

a function R => A

Returns:

a new function f such that f(x) == g(apply(x))

Inherited from:
Function1
Source:
Function1.scala
def compose[A](g: A => T): A => U

Composes two instances of Function1 in a new Function1, with this function applied last.

Composes two instances of Function1 in a new Function1, with this function applied last.

Type parameters:
A

the type to which function g can be applied

Value parameters:
g

a function A => T1

Returns:

a new function f such that f(x) == apply(g(x))

Inherited from:
Function1
Source:
Function1.scala
override def toString(): String
Definition Classes
Inherited from:
Function1
Source:
Function1.scala

Extensions

Extensions

extension (x: T)
def convert: U

x.convert converts a value x of type T to type U

x.convert converts a value x of type T to type U

Source:
Conversion.scala