The method isDefinedAt() is an abstract value member of trait PartialFunction, which is identical to the method contains and is observed in all the classes of PartialFunction. It inspects whether a value is contained in the function’s domain or not.
-
Method Definition:
abstract def isDefinedAt(x: A): Boolean
where, x is the value to be tested.
-
Return Type:
It returns true if x is present in the domain of this function else returns false.
Example :
// Scala program of isDefinedAt() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating partial function val par : PartialFunction[Int,Int] = { case 1 => 1 } // Applying isDefinedAt() method val result = par.isDefinedAt(1) // Displays output println(result) } } |
true
Here, the value i.e, x defined above is present in the function domain so, it returns true.
Example :
// Scala program of isDefinedAt() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a map val map: Map[Int,Int] = Map(2 -> 3) // Applying isDefinedAt() method val result = map.isDefinedAt(5) // Displays output println(result) } } |
false
Here, the value i.e, x defined above is not present in the function domain so, it returns false.
Recommended Posts:
- Scala Set +() method with example
- Scala Set -() method with example
- Scala Int ==(x: Int) method with example
- Scala Set contains() method with example
- Scala Map take() method with example
- Scala Set &~() method with example
- Scala Int !=(x: Int) method with example
- Scala Int -(x: Int) method with example
- Scala Int /(x: Int) method with example
- Scala Set max() method with example
- Scala Set min() method with example
- Scala Int <=(x: Int) method with example
- Scala Set sum() method with example
- Scala Set take() method with example
- Scala Map last() method with example
- Scala Map min() method with example
- Scala Map max() method with example
- Scala Set ++() method with example
- Scala Int %(x: Int) method with example
- Scala Int >>>(x: Int) method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

