All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.peterpotts.example.ExamplePrimitive.scala Maven / Gradle / Ivy

The newest version!
package com.peterpotts.example

import scalaz.Scalaz._

trait ExamplePrimitive {
  self: ExampleMonad =>

  val defaultSize = 4

  val exampleLong: Example[Long] = Example[Long](identity)

  val exampleInt: Example[Int] = Example(_.toInt)

  def exampleInt(until: Int): Example[Int] = exampleInt.map(math.abs).map(_ % until)

  val exampleBoolean: Example[Boolean] = Example(_ > 0)

  val exampleByte: Example[Byte] = Example(_.toByte)

  val exampleDouble: Example[Double] =
    for {
      wholePart <- exampleLong
      fractionalPart <- exampleLong
    } yield wholePart.toDouble + (fractionalPart.toDouble / Long.MaxValue.toDouble)

  val exampleUnit: Example[Unit] = Example(_ => ())

  def exampleLift[A](a: A): Example[A] = a.point[Example]
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy