Skip to content

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

Merged
merged 1 commit into from
Apr 13, 2020
Merged

SCALA-45 Partial Functions #30

merged 1 commit into from
Apr 13, 2020

Conversation

barbasa
Copy link
Contributor

@barbasa barbasa commented Mar 21, 2020

No description provided.

Copy link
Contributor

@glmartin glmartin left a 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?

@barbasa
Copy link
Contributor Author

barbasa commented Mar 28, 2020

@glmartin Makes sense. Unit tests added.

Copy link
Contributor

@KevinGilmore KevinGilmore left a 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

Comment on lines 4 to 11
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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use two-space indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 5 to 15
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two-space indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@barbasa barbasa requested a review from KevinGilmore April 7, 2020 13:48
@lor6 lor6 merged commit 5bb2ae6 into Baeldung:master Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants