Created
February 11, 2016 13:04
-
-
Save benhutchison/e70315e15b5b6aff1764 to your computer and use it in GitHub Desktop.
Is the firstNonEmpty Monoid lawful? Lets get an opinion from the LawBot that Cats & friends use...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome to the Ammonite Repl 0.5.1 | |
(Scala 2.11.7 Java 1.8.0_66) | |
ben_hutchison-ben_hutchison@ load.ivy("org.typelevel" %% "cats" % "0.4.1") | |
ben_hutchison-ben_hutchison@ load.ivy("org.typelevel" %% "alleycats-core" % "0.1.3") | |
ben_hutchison-ben_hutchison@ import cats._, cats.std.all._ | |
import cats._, cats.std.all._ | |
ben_hutchison-ben_hutchison@ import alleycats._ | |
import alleycats._ | |
ben_hutchison-ben_hutchison@ implicit val el = new EmptyK[List] { def empty[A] = List.empty[A] } | |
el: AnyRef with EmptyK[List] = cmd4$$anon$1@46d7c4d0 | |
ben_hutchison-ben_hutchison@ implicit def firstNonEmpty[F[_], A](implicit F: Foldable[F], E: EmptyK[F]) = new Monoid[F[A]]{ | |
def empty = E.empty[A] | |
def combine(x: F[A], y: F[A]): F[A] = if (F.nonEmpty(y)) y else x | |
} | |
defined function firstNonEmpty | |
ben_hutchison-ben_hutchison@ import algebra.laws.GroupLaws | |
import algebra.laws.GroupLaws | |
ben_hutchison-ben_hutchison@ val rs2 = GroupLaws[List[Int]].monoid(firstNonEmpty[List, Int]) | |
rs2: (AnyRef with GroupLaws[List[Int]])#GroupProperties = algebra.laws.GroupLaws$GroupProperties@19a78a4f | |
ben_hutchison-ben_hutchison@ rs2.all.check | |
+ monoid.associativity: OK, passed 100 tests. | |
+ monoid.combineAll(Nil) == id: OK, passed 100 tests. | |
+ monoid.combineN(a, 0) == id: OK, passed 100 tests. | |
+ monoid.combineN(a, 1) == a: OK, passed 100 tests. | |
+ monoid.combineN(a, 2) == a |+| a: OK, passed 100 tests. | |
+ monoid.isEmpty: OK, passed 100 tests. | |
+ monoid.leftIdentity: OK, passed 100 tests. | |
+ monoid.rightIdentity: OK, passed 100 tests. | |
+ monoid.serializable: OK, proved property. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment