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

Scala example source code file (KleisliOps.scala)

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

anyval, kleisli, kleislifaops, kleisliidops, readert, tokleislifaops, tokleisliidops, tokleisliops0, tokleisliopsunapply, unapply

The KleisliOps.scala Scala example source code

package scalaz
package syntax

import Id._

final class KleisliIdOps[A](val self: A) extends AnyVal {
  /** Lift the value into a Kleisli */
  def liftKleisliId[R]: Kleisli[Id, R, A] = Kleisli[Id, R, A](_ => self)

  /** Lift the value into a Reader. Alias for liftKleisliId */
  def liftReader[R]: Reader[R, A] = liftKleisliId
}

final class KleisliFAOps[F[_], A](val self: F[A]) extends AnyVal {
  /** Lift the computation into a Kleisli */
  def liftKleisli[R]: Kleisli[F, R, A] = Kleisli[F, R, A](_ => self)

  /** Lift the computation into a ReaderT. Alias for liftKleisli */
  def liftReaderT[R]: ReaderT[F, R, A] = liftKleisli
}

sealed trait ToKleisliOps0 {
  implicit def ToKleisliOpsUnapply[FA](v: FA)(implicit F0: Unapply[Monad, FA]): KleisliFAOps[F0.M, F0.A] =
    new KleisliFAOps(F0(v))
}

trait ToKleisliOps extends ToKleisliOps0 {
  implicit def ToKleisliIdOps[A](a: A) = new KleisliIdOps(a)
  implicit def ToKleisliFAOps[F[_], A](fa: F[A]) = new KleisliFAOps(fa)
}

Other Scala examples (source code examples)

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



my book on functional programming

 

new blog posts

 

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