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

Scala example source code file (EndomorphicTest.scala)

This example Scala source code file (EndomorphicTest.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

arbitrary, category, cobind, comonad, endomorphictest, equal, int, monad, monoid, semigroup

The EndomorphicTest.scala Scala example source code

package scalaz

import scalaz.scalacheck.ScalazProperties._
import scalaz.scalacheck.ScalaCheckBinding._
import scalaz.scalacheck.ScalazArbitrary._
import org.scalacheck.Arbitrary
import KleisliTest._
import CokleisliTest._
import std.AllInstances._

object EndomorphicTest extends SpecLite {

  implicit def endoEqual[F[_], G[_[_], _, _], A](
    implicit F: Equal[G[F, A, A]]
  ): Equal[Endomorphic[G[F, ?, ?], A]] =
    Equal.equalBy(_.run)

  implicit def endoArb[F[_], G[_[_], _, _], A](
    implicit F: Arbitrary[G[F, A, A]]
  ): Arbitrary[Endomorphic[G[F, ?, ?], A]] =
    Functor[Arbitrary].map(F)(Endomorphic[G[F, ?, ?], A](_))

  checkAll(monoid.laws[Endomorphic[Kleisli[Option, ?, ?], Int]])
  checkAll(semigroup.laws[Endomorphic[Cokleisli[Option, ?, ?], Int]])

  object instances{
    def semigroup[F[_, _]: Compose, A] = Semigroup[Endomorphic[F, A]]
    def monoid[F[_, _]: Category, A] = Monoid[Endomorphic[F, A]]

    def semigroup[F[_, _]: Category, A] = Semigroup[Endomorphic[F, A]]

    object kleisli {
      def semigroup[F[_]: Bind, A] = Semigroup[Endomorphic[Kleisli[F, ?, ?], A]]
      def monoid[F[_]: Monad, A] = Monoid[Endomorphic[Kleisli[F, ?, ?], A]]

      def semigroup[F[_]: Monad, A] = Semigroup[Endomorphic[Kleisli[F, ?, ?], A]]
    }

    object cokleisli {
      def semigroup[F[_]: Cobind, A] = Semigroup[Endomorphic[Cokleisli[F, ?, ?], A]]
      def monoid[F[_]: Comonad, A] = Monoid[Endomorphic[Cokleisli[F, ?, ?], A]]

      def semigroup[F[_]: Comonad, A] = Semigroup[Endomorphic[Cokleisli[F, ?, ?], A]]
    }
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala EndomorphicTest.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.