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/<:<

<:<

scala.<:<
See the<:< companion object
sealed abstractclass<:<[-From,+To] extendsFrom=>To,Serializable

An instance ofA <:< B witnesses thatA is a subtype ofB. Requiring an implicit argument of the typeA <:< B encodes the generalized constraintA <: B.

To constrain any abstract typeT that's in scope in a method's argument list (not just the method's own type parameters) simply add an implicit argument of typeT <:< U, whereU is the required upper bound; or for lower-bounds, use:L <:< T, whereL is the required lower bound.

In case of any confusion over which method goes in what direction, all the "Co" methods (includingapply) go from left to right in the type ("with" the type), and all the "Contra" methods go from right to left ("against" the type). E.g.,apply turns aFrom into aTo, andsubstituteContra replaces theTos in a type withFroms.

In part contributed by Jason Zaugg.

Type parameters

From

a type which is proved a subtype ofTo

To

a type which is proved a supertype ofFrom

Attributes

See also

=:= for expressing equality constraints

Example

scala.Option#flatten

sealed trait Option[+A] {  // def flatten[B, A <: Option[B]]: Option[B] = ...  // won't work, since the A in flatten shadows the class-scoped A.  def flatten[B](implicit ev: A <:< Option[B]): Option[B]    = if(isEmpty) None else ev(get)  // Because (A <:< Option[B]) <: (A => Option[B]), ev can be called to turn the  // A from get into an Option[B], and because ev is implicit, that call can be  // left out and inserted automatically.}
Companion
object
Source
typeConstraints.scala
Graph
Supertypes
traitFrom=>To
classObject
traitMatchable
classAny
Known subtypes
classFrom=:=To

Members list

Value members

Abstract methods

defsubstituteBoth[F[_,_]](ftf:F[To,From]):F[From,To]

SubstituteTo forFrom andFrom forTo in the typeF[To, From], given thatF is contravariant in the first argument and covariant in the second.

SubstituteTo forFrom andFrom forTo in the typeF[To, From], given thatF is contravariant in the first argument and covariant in the second. Essentially swapsTo andFrom inftf's type.

Equivalent in power to each ofsubstituteCo andsubstituteContra.

This method is impossible to implement withoutthrowing or otherwise "cheating" unlessFrom <: To, so it ensures that this really represents a subtyping relationship.

Attributes

Returns

ftf, but with a (potentially) different type

Source
typeConstraints.scala

Concrete methods

overridedefandThen[C](r:To=>C):From=>C

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))

Definition Classes
Source
typeConstraints.scala
defandThen[C](r:To<:<C):From<:<C

IfFrom <: To andTo <: C, thenFrom <: C (subtyping is transitive)

IfFrom <: To andTo <: C, thenFrom <: C (subtyping is transitive)

Attributes

Source
typeConstraints.scala
overridedefapply(f:From):To

Coerce aFrom into aTo.

Coerce aFrom into aTo. This is guaranteed to be the identity function.

This method is often called implicitly as an implicitA <:< B doubles as an implicit viewA => B.

Value parameters

f

some value of typeFrom

Attributes

Returns

f, but with a (potentially) different type

Definition Classes
Source
typeConstraints.scala
overridedefcompose[C](r:C=>From):C=>To

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))

Definition Classes
Source
typeConstraints.scala
defcompose[C](r:C<:<From):C<:<To

IfFrom <: To andC <: From, thenC <: To (subtyping is transitive)

IfFrom <: To andC <: From, thenC <: To (subtyping is transitive)

Attributes

Source
typeConstraints.scala
defliftCo[F[_]]:F[From]<:<F[To]

Lift this evidence over a covariant type constructorF.

Lift this evidence over a covariant type constructorF.

Attributes

Source
typeConstraints.scala
defliftContra[F[_]]:F[To]<:<F[From]

Lift this evidence over a contravariant type constructorF.

Lift this evidence over a contravariant type constructorF.

Attributes

Source
typeConstraints.scala
defsubstituteCo[F[_]](ff:F[From]):F[To]

Substitute theFrom in the typeF[From], whereF is a covariant type constructor, forTo.

Substitute theFrom in the typeF[From], whereF is a covariant type constructor, forTo.

Equivalent in power to each ofsubstituteBoth andsubstituteContra.

This method is impossible to implement withoutthrowing or otherwise "cheating" unlessFrom <: To, so it ensures that this really represents a subtyping relationship.

Attributes

Returns

ff, but with a (potentially) different type

Source
typeConstraints.scala
defsubstituteContra[F[_]](ft:F[To]):F[From]

Substitute theTo in the typeF[To], whereF is a contravariant type constructor, forFrom.

Substitute theTo in the typeF[To], whereF is a contravariant type constructor, forFrom.

Equivalent in power to each ofsubstituteBoth andsubstituteCo.

This method is impossible to implement withoutthrowing or otherwise "cheating" unlessFrom <: To, so it ensures that this really represents a subtyping relationship.

Attributes

Returns

ft, but with a (potentially) different type

Source
typeConstraints.scala

Inherited methods

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
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp