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

PartialFunction

scala.PartialFunction
See thePartialFunction companion trait

A few handy operations which leverage the extra bit of information available in partial functions. Examples:

import PartialFunction._def strangeConditional(other: Any): Boolean = cond(other) {  case x: String if x == "abc" || x == "def"  => true  case x: Int => true}def onlyInt(v: Any): Option[Int] = condOpt(v) { case x: Int => x }

Attributes

Companion
trait
Source
PartialFunction.scala
Graph
Supertypes
classObject
traitMatchable
classAny
Self type

Members list

Type members

Classlikes

finalclassElementWiseExtractor[-A,+B] extendsAnyVal

Attributes

Source
PartialFunction.scala
Supertypes
classAnyVal
traitMatchable
classAny

Value members

Concrete methods

A Boolean test that is the result of the given function where defined, and false otherwise.

A Boolean test that is the result of the given function where defined, and false otherwise.

It behaves like acase _ => false were added to the partial function.

Value parameters

pf

the partial function

x

the value to test

Attributes

Returns

true, iffx is in the domain ofpf andpf(x) == true.

Source
PartialFunction.scala
defcondOpt[A,B](x:A)(pf:PartialFunction[A,B]):Option[B]

Apply the function to the given value if defined, and return the result in aSome; otherwise, returnNone.

Apply the function to the given value if defined, and return the result in aSome; otherwise, returnNone.

Value parameters

pf

the PartialFunction[T, U]

x

the value to test

Attributes

Returns

Some(pf(x)) ifpf isDefinedAt x,None otherwise.

Source
PartialFunction.scala
defempty[A,B]:PartialFunction[A,B]

The partial function with empty domain.

The partial function with empty domain. Any attempt to invoke empty partial function leads to throwingscala.MatchError exception.

Attributes

Source
PartialFunction.scala
deffromFunction[A,B](f:A=>B):PartialFunction[A,B]

Converts an ordinary function to a partial function.

Converts an ordinary function to a partial function. Note that callingisDefinedAt(x) on this partial function will returntrue for everyx.

Value parameters

f

an ordinary function

Attributes

Returns

a partial function which delegates to the ordinary functionf

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

[8]ページ先頭

©2009-2025 Movatter.jp