Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/Conversion

Conversion

scala.Conversion
See theConversion companion object
@FunctionalInterface
abstractclassConversion[-T,+U] extendsT=>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 inImplicits#discardForView which emulates the conversion in a more efficient way.

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

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

TheConversion class can also be used to convert explicitly, using theconvert extension method.

Attributes

Companion
object
Source
Conversion.scala
Graph
Supertypes
traitT=>U
classObject
traitMatchable
classAny

Members list

Value members

Abstract methods

defapply(x:T):U

Convert valuex of typeT to typeU

Convert valuex of typeT to typeU

Attributes

Source
Conversion.scala

Inherited methods

defandThen[A](g:U=>A):T=>A

Composes two instances ofFunction1 in a newFunction1, with this function applied first.

Composes two instances ofFunction1 in a newFunction1, with this function applied first.

Type parameters

A

the result type of functiong

Value parameters

g

a function R => A

Attributes

Returns

a new functionf such thatf(x) == g(apply(x))

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

Composes two instances ofFunction1 in a newFunction1, with this function applied last.

Composes two instances ofFunction1 in a newFunction1, with this function applied last.

Type parameters

A

the type to which functiong can be applied

Value parameters

g

a function A => T1

Attributes

Returns

a new functionf such thatf(x) == apply(g(x))

Inherited from:
Function1
Source
Function1.scala
overridedeftoString():String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Inherited from:
Function1
Source
Function1.scala

Extensions

Extensions

extension(x:T)
defconvert:U

x.convert converts a valuex of typeT to typeU

x.convert converts a valuex of typeT to typeU

Attributes

Source
Conversion.scala
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp