|
Scala example source code file (PartialFunctionTest.scala)
The PartialFunctionTest.scala Scala example source code
package scalaz
package std
import std.AllInstances._
import org.scalacheck.Prop.forAll
object PartialFunctionTest extends SpecLite {
private type PF[-A, +B] = PartialFunction[A, B]
private val A = Arrow[PartialFunction]
private val pfnegonly: PF[Int, Int] = {case a if a < 0 => 0 - a}
private val pfposonly: PF[Int, Int] = {case a if a >= 0 => 0 - a}
"arrow equivalence" ! forAll {
(num: Int, num2: Int) =>
val nums = (num, num2)
A.split(A.id[Int], A.id[Int]).isDefinedAt(nums) must_===(true)
A.split(A.id[Int], A.id[Int])(nums) must_===(nums)
val definedness = for {
l <- List(pfnegonly, pfposonly)
r <- List(pfnegonly, pfposonly)
} yield (A.split(l, r), A.split(l, r) isDefinedAt (nums))
(definedness.find(_._2).get._1(nums)
must_===((0 - num, 0 - num2)))
}
}
Other Scala examples (source code examples)Here is a short list of links related to this Scala PartialFunctionTest.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.