Partial functions are functions which are not defined for all of their inputs. For questions about partially applied functions, use [partial-application] instead.
Questions tagged [partial-functions]
35 questions
0
votes
1 answer
Pattern-matching: split code with PartialFunction?
I'm struggling to achieve a "simple" behaviour: divide pattern matching code in two separate functions.
I'm simplifying the model for clearness purpose:
abstract class Animal
case object Dog extends Animal
case object Cat extends Animal
case object…

Nicolas Cailloux
- 418
- 4
- 13
0
votes
2 answers
Combining partial functions
I came from Java and would like to combine two partial functions like this:
def sum(a: Int, b: Int, c: Int) : Int = a + b + c
I want write something like this:
val l = List(1, 2, 3)
l.foreach(println _ sum (1, _ : Int, 3) ) // It's supposed to…

user3663882
- 6,957
- 10
- 51
- 92
0
votes
2 answers
How does the extractor work when the `unapply` function returns Boolean instead of Option?
I learned about extractors from the stairway book:
object Twice {
def apply(x: Int) = x * 2
def unapply(x: Int) = if(x % 2 == 0) Some(x / 2) else None
}
// outside pattern mathcing, Twice.apply(21) is called
val x =…

qed
- 22,298
- 21
- 125
- 196
0
votes
1 answer
Can I apply argument defaults when using partial functions in Scala
I have defined two partial functions (hashes), which I expect to take an optional second Boolean parameter:
def SHA1 = hash(MessageDigest.getInstance("SHA-1"))_
def MD5 = hash(MessageDigest.getInstance("MD5"))_
private def…

climmunk
- 1,141
- 1
- 12
- 29
-2
votes
2 answers
How to take a constant Integer as input in Partial Function?
I am new to scala, I have a use case where I want to define a partial function to add three numbers in which one number is constant and two
numbers can be passed as inputs and define another method which can take the partial
function as input and…

R.Gold
- 95
- 2
- 10