-
Notifications
You must be signed in to change notification settings - Fork 214
SCALA-45 Partial Functions #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The examples look good. However, we like to show them using unit tests. You can keep these examples as they are, but can you add some unit tests?
@glmartin Makes sense. Unit tests added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two-space indent, ScalaTest
val squareRoot = new PartialFunction[Double, Double] { | ||
def apply(x: Double) = Math.sqrt(x) | ||
def isDefinedAt(x: Double) = x >= 0 | ||
} | ||
|
||
val squareRootImplicit: PartialFunction[Double, Double] = { | ||
case x if x >= 0 => Math.sqrt(x) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use two-space indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
private val negativeOrZeroToPositive: PartialFunction[Int, Int] = { | ||
case x if x <= 0 => Math.abs(x) | ||
} | ||
|
||
private val positiveToNegative: PartialFunction[Int, Int] = { | ||
case x if x > 0 => -1 * x | ||
} | ||
|
||
val swapSign: PartialFunction[Int, Int] = { | ||
positiveToNegative orElse negativeOrZeroToPositive | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two-space indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
No description provided.