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

Function1

scala.Function1
See theFunction1 companion object
traitFunction1[-T1,+R] extendsAnyRef

A function of 1 parameter.

In the following example, the definition ofsucc is shorthand, conceptually, for the anonymous class definitionanonfun1, although the implementation details of how the function value is constructed may differ:

object Main extends App {  val succ = (x: Int) => x + 1  val anonfun1 = new Function1[Int, Int] {    def apply(x: Int): Int = x + 1  }  assert(succ(0) == anonfun1(0))}

Note that the difference betweenFunction1 andscala.PartialFunction is that the latter can specify inputs which it will not handle.

Attributes

Companion
object
Source
Function1.scala
Graph
Supertypes
classObject
traitMatchable
classAny
Known subtypes
traitSetOps[A,CC,C]
traitSetOps[A,CC,C]
traitSet[A]
classAbstractSet[A]
classBitSet
classBitSet1
classBitSet2
classBitSetN
classHashSet[A]
classListSet[A]
classSet1[A]
classSet2[A]
classSet3[A]
classSet4[A]
classTreeSet[A]
traitSortedSet[A]
traitSortedSetOps[A,CC,C]
traitStrictOptimizedSetOps[A,CC,C]
traitSetOps[A,CC,C]
classHashSet[A]
classLinkedHashSet[A]
traitSet[A]
classAbstractSet[A]
classBitSet
classTreeSet[A]
traitSortedSet[A]
traitSortedSetOps[A,CC,C]
traitSet[A]
classAbstractSet[A]
traitSortedSet[A]
traitBitSet
traitSortedSetOps[A,CC,C]
traitBitSetOps[C]
traitSortedSetFactoryDefaults[A,CC,WithFilterCC]
traitStrictOptimizedSetOps[A,CC,C]
classFromJavaFunction[T,R]
classAbstractFunction1[T1,R]
classFrom<:<To
classFrom=:=To
classConversion[T,U]
traitPartialFunction[A,B]
traitMapOps[K,V,CC,C]
traitMapOps[K,V,CC,C]
traitMap[K,V]
classAbstractMap[K,V]
classHashMap[K,V]
classIntMap[T]
classListMap[K,V]
classLongMap[T]
classMap1[K,V]
classMap2[K,V]
classMap3[K,V]
classMap4[K,V]
classWithDefault[K,V]
classWithDefault[K,V]
classTreeMap[K,V]
classTreeSeqMap[K,V]
classVectorMap[K,V]
traitSeqMap[K,V]
traitSortedMap[K,V]
traitSortedMapOps[K,V,CC,C]
traitStrictOptimizedMapOps[K,V,CC,C]
traitMapOps[K,V,CC,C]
classTrieMap[K,V]
classAnyRefMap[K,V]
classHashMap[K,V]
classLinkedHashMap[K,V]
classListMap[K,V]
classLongMap[V]
traitMap[K,V]
traitMap[K,V]
classAbstractMap[K,V]
classWithDefault[K,V]
classWithDefault[K,V]
classOpenHashMap[Key,Value]
classTreeMap[K,V]
traitMultiMap[K,V]
traitSeqMap[K,V]
traitSortedMap[K,V]
traitSortedMapOps[K,V,CC,C]
traitMap[K,V]
classAbstractMap[K,V]
traitDefaultMap[K,V]
traitSeqMap[K,V]
traitSortedMap[K,V]
traitMapFactoryDefaults[K,V,CC,WithFilterCC]
classWeakHashMap[K,V]
traitMapView[K,V]
classAbstractMapView[K,V]
classFilter[K,V]
classFilterKeys[K,V]
classId[K,V]
classMapValues[K,V,W]
classTapEach[K,V,U]
traitSortedMapFactoryDefaults[K,V,CC,WithFilterCC,UnsortedCC]
traitSortedMapOps[K,V,CC,C]
traitStrictOptimizedMapOps[K,V,CC,C]
traitSeq[A]
traitSeq[A]
classAbstractSeq[A]
classArraySeq[A]
classofBoolean
classofByte
classofChar
classofDouble
classofFloat
classofInt
classofLong
classofRef[T]
classofShort
classofUnit
classLazyList[A]
classList[A]
class::[A]
objectNil
classNumericRange[T]
classExclusive[T]
classInclusive[T]
classQueue[A]
classRange
classExclusive
classInclusive
classStream[A]
classCons[A]
objectEmpty
classVector[A]
traitIndexedSeq[A]
traitLinearSeq[A]
traitSeq[A]
classAbstractSeq[A]
classArrayBuffer[A]
classArrayDeque[A]
classQueue[A]
classStack[A]
classListBuffer[A]
classArraySeq[T]
classofBoolean
classofByte
classofChar
classofDouble
classofFloat
classofInt
classofLong
classofRef[T]
classofShort
classofUnit
traitBuffer[A]
traitIndexedBuffer[A]
traitIndexedSeq[T]
classAccumulator[A,CC,C]
classAbstractSeq[A]
traitIndexedSeq[A]
traitLinearSeq[A]
Show all
Self type
T1=>R

Members list

Value members

Abstract methods

defapply(v1:T1):R

Apply the body of this function to the argument.

Apply the body of this function to the argument.

Attributes

Returns

the result of function application.

Source
Function1.scala

Concrete methods

defandThen[A](g:R=>A):T1=>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))

Source
Function1.scala
defcompose[A](g:A=>T1):A=>R

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

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
Source
Function1.scala
Implicitly added byUnliftOps

Converts an optional function to a partial function.

Converts an optional function to a partial function.

Attributes

Example

UnlikeFunction.unlift, thisUnliftOps.unlift method can be used in extractors.

val of: Int => Option[String] = { i =>  if (i == 2) {    Some("matched by an optional function")  } else {    None  }}util.Random.nextInt(4) match {  case of.unlift(m) => // Convert an optional function to a pattern    println(m)  case _ =>    println("Not matched")}
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