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

Scala example source code file (CoproductTest.scala)

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

cobind, comonad, contravariant, foldable, foldable1, functor, invariantfunctor, nonemptylist, speclite, traverse, traverse1, tree

The CoproductTest.scala Scala example source code

package scalaz

import std.AllInstances._
import scalaz.scalacheck.ScalazProperties._
import scalaz.scalacheck.ScalazArbitrary._

object CoproductTest extends SpecLite {

  checkAll(comonad.laws[Coproduct[NonEmptyList, Tree, ?]])
  checkAll(traverse.laws[Coproduct[Option, List, ?]])
  checkAll(traverse1.laws[Coproduct[NonEmptyList, NonEmptyList, ?]])

  object instances {
    def functor[F[_]: Functor, G[_]: Functor] = Functor[Coproduct[F, G, ?]]
    def foldable[F[_]: Foldable, G[_]: Foldable] = Foldable[Coproduct[F, G, ?]]
    def foldable1[F[_]: Foldable1, G[_]: Foldable1] = Foldable1[Coproduct[F, G, ?]]
    def contravariant[F[_]: Contravariant, G[_]: Contravariant] = Contravariant[Coproduct[F, G, ?]]
    def cobind[F[_]: Cobind, G[_]: Cobind] = Cobind[Coproduct[F, G, ?]]
    def traverse[F[_]: Traverse, G[_]: Traverse] = Traverse[Coproduct[F, G, ?]]
    def traverse1[F[_]: Traverse1, G[_]: Traverse1] = Traverse1[Coproduct[F, G, ?]]
    def comonad[F[_]: Comonad, G[_]: Comonad] = Comonad[Coproduct[F, G, ?]]

    // checking absence of ambiguity
    def invariantfunctor[F[_]: Comonad: Traverse: Contravariant, G[_]: Comonad: Traverse: Contravariant] = InvariantFunctor[Coproduct[F, G, ?]]
    def invariantfunctor[F[_]: Functor: Contravariant, G[_]: Functor: Contravariant] = InvariantFunctor[Coproduct[F, G, ?]]
    def functor[F[_]: Comonad: Traverse, G[_]: Comonad: Traverse] = Functor[Coproduct[F, G, ?]]
    def foldable[F[_]: Traverse, G[_]: Traverse] = Foldable[Coproduct[F, G, ?]]
    def foldable[F[_]: Traverse1, G[_]: Traverse1] = Foldable[Coproduct[F, G, ?]]
    def traverse[F[_]: Traverse1, G[_]: Traverse1] = Traverse[Coproduct[F, G, ?]]
    def foldable1[F[_]: Traverse1, G[_]: Traverse1] = Foldable1[Coproduct[F, G, ?]]
    def cobind[F[_]: Comonad, G[_]: Comonad] = Cobind[Coproduct[F, G, ?]]
  }
}

Other Scala examples (source code examples)

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