alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (CodensityTest.scala)

This example Scala source code file (CodensityTest.scala) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Scala by Example" TM.

Learn more about this Scala project at its project page.

Java - Scala tags/keywords

applicative, apply, arbitrary, codensitytest, equal, functor, list, monad, monadplus, option, speclite

The CodensityTest.scala Scala example source code

package scalaz

import org.scalacheck.Arbitrary
import scalaz.scalacheck.ScalazProperties._
import scalaz.scalacheck.ScalaCheckBinding._
import std.list._
import std.anyVal._
import std.option._

object CodensityTest extends SpecLite {
  implicit def arbCodensity[F[_], A](implicit A: Arbitrary[F[A]], M: Monad[F])
      : Arbitrary[Codensity[F, A]] =
    Functor[Arbitrary].map(A)(Codensity.rep(_))

  implicit def eqlCodensity[F[_], A](implicit A: Equal[F[A]], M: Applicative[F])
      : Equal[Codensity[F, A]] =
    Equal.equalBy(_.improve)

  checkAll("List", monadPlus.laws[Codensity[List, ?]])
  checkAll("Option", monadPlus.laws[Codensity[Option, ?]])

  object instances {
    def functor[F[_]: MonadPlus] = Functor[Codensity[F, ?]]
    def apply[F[_]: MonadPlus] = Apply[Codensity[F, ?]]
    def applicative[F[_]: MonadPlus] = Applicative[Codensity[F, ?]]
    def plus[F[_]: MonadPlus] = Plus[Codensity[F, ?]]
    def monad[F[_]: MonadPlus] = Monad[Codensity[F, ?]]
    def monade[F[_]] = Monad[Codensity[F, ?]]
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala CodensityTest.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 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.