|
Scala example source code file (TagTest.scala)
The TagTest.scala Scala example source codepackage scalaz import scalaz.scalacheck.ScalazArbitrary._ import std.AllInstances._ import Tags.{Multiplication => Mult} import org.scalacheck.Prop.forAll object TagTest extends SpecLite { "of.subst" should { "substitute" ! forAll {xs: List[Int] => (Tag unwrap Foldable[List].fold(Tag.of[Mult].subst(xs)) must_===(xs.foldLeft(1)(_ * _))) } } "of.onF" should { "substitute" ! forAll {xs: List[List[Unit]] => (Tag unwrap (Foldable[List].foldMap(xs)(Tag.of[Mult].onF(_.length))) must_===(xs.foldLeft(1)((n, l) => n * l.length))) } } "of.onCov" should { "choose covariant position" in { Tag.of[Mult].onCov((a:Int) => a): (Int => (Int @@ Mult)) true } } "of.onContra" should { "choose contravariant position" in { Tag.of[Mult].onContra(Show[Int]): Show[Int @@ Mult] true } } "of.unsubst" should { "substitute" in { Tag.of[Mult].unsubst(Semigroup[Int @@ Mult]): Semigroup[Int] true } } "of.unapply" should { "support unwrapping in pattern match" in { Monoid[Int @@ Mult].append(Mult(3), Mult(3)) match { case Mult(9) ⇒ true case Mult(_) ⇒ false } } } } Other Scala examples (source code examples)Here is a short list of links related to this Scala TagTest.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.