| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (TryTest.scala)

This example Scala source code file (TryTest.scala) is included in the "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

equal, failure, int, show, speclite, success, throwable, trytest, validation

The TryTest.scala Scala example source code

package scalaz
package std

import std.AllInstances._
import scalaz.scalacheck.ScalazArbitrary._
import org.scalacheck.Prop.forAll
import scala.util.{Failure, Success}

object TryTest extends SpecLite {

  // these probably aren't a great idea, but they are just for tests
  implicit val showThrowable: Show[Throwable] = Show.showA
  implicit val equalThrowable: Equal[Throwable] = Equal.equalA

  "toDisjunction Failure" ! forAll { t: Throwable =>

  "toDisjunction Success" ! forAll { i: Int =>

  "disjunction round trip" ! forAll { d: Throwable \/ Int =>
    val iso = `try`.tryDisjunctionIso must_=== d

  "toValidation Failure" ! forAll { t: Throwable =>

  "toValidation Success" ! forAll { i: Int =>

  "toValidationNel Failure" ! forAll {t: Throwable =>

  "toValidationNel Success" ! forAll {i: Int =>

  "validation round trip" ! forAll { v: Validation[Throwable, Int] =>
    val iso = `try`.tryValidationIso must_=== v

Other Scala examples (source code examples)

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