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

Scala example source code file (MaybeTTest.scala)

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

bindrec, foldable, functor, int, intor, maybet, maybetlist, maybettest, monad, monaderror, speclite, traverse

The MaybeTTest.scala Scala example source code

package scalaz

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

object MaybeTTest extends SpecLite {

  type MaybeTList[A] = MaybeT[List, A]
  type IntOr[A] = Int \/ A
  type MaybeTEither[A] = MaybeT[IntOr, A]

  checkAll(equal.laws[MaybeTList[Int]])
  checkAll(bindRec.laws[MaybeTList])
  checkAll(monadPlus.laws[MaybeTList])
  checkAll(traverse.laws[MaybeTList])
  checkAll(monadError.laws[MaybeTEither, Int])

  object instances {
    def functor[F[_] : Functor] = Functor[MaybeT[F, ?]]
    def monad[F[_] : Monad] = MonadPlus[MaybeT[F, ?]]
    def bindRec[F[_] : Monad : BindRec] = BindRec[MaybeT[F, ?]]
    def monadError[F[_], E](implicit F: MonadError[F, E]) = MonadError[MaybeT[F, ?], E]
    def foldable[F[_] : Foldable] = Foldable[MaybeT[F, ?]]
    def traverse[F[_] : Traverse] = Traverse[MaybeT[F, ?]]

    // checking absence of ambiguity
    def functor[F[_] : Monad] = Functor[MaybeT[F, ?]]
    def functor[F[_] : Monad : Traverse] = Functor[MaybeT[F, ?]]
    def functor[F[_], E](implicit F1: MonadError[F, E], F2: Traverse[F]) = Functor[MaybeT[F, ?]]
    def apply[F[_] : Monad] = Apply[MaybeT[F, ?]]
    def foldable[F[_] : Traverse] = Foldable[MaybeT[F, ?]]
    def monadEither[E] = Monad[MaybeT[E \/ ?, ?]]
  }
}

Other Scala examples (source code examples)

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