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

Scala example source code file (InvariantFunctorTest.scala)

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

bijection, int, invariantfunctortest, isoset, num, speclite

The InvariantFunctorTest.scala Scala example source code

package scalaz

import BijectionT.{Bijection, liftBijection}
import Id.Id
import Isomorphism.{<=>, IsoSet}
import std.AllInstances._
import std.option.some
import syntax.invariantFunctor._

object InvariantFunctorTest extends SpecLite {

  "xmap" in {
    some(1).xmap[Int](_ + 1, _ - 1) must_===(some(2))
  }

  "xmap iso" in {
    val succI: Int <=> Int = new IsoSet[Int, Int] {
      def to = (_: Int) + 1
      def from = (_: Int) - 1
    }
    some(1) xmapi succI must_===(some(2))
  }

  "xmap bijection" in {
    val succB: Bijection[Int, Int] = liftBijection[Id, Id, Int, Int](_ + 1, _ - 1)
    some(1) xmapb succB must_===(some(2))
  }

  case class Num(x: Int)
  implicit val showNum = Show.showA[Num]
  implicit val eqNum = Equal.equalA[Num]
}

Other Scala examples (source code examples)

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

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

#1 New Release!

FP Best Seller

 

new blog posts

 

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