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

Scala example source code file (Compose.scala)

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

Java - Scala tags/keywords

boolean, compose, composelaw, composeplus, composesemigroup, plus, semigroup

The Compose.scala Scala example source code

```package scalaz

////
/**
*
*/
////
trait Compose[=>:[_, _]]  { self =>
////

/** Associative `=>:` binary operator. */
def compose[A, B, C](f: B =>: C, g: A =>: B): (A =>: C)

protected[this] trait ComposePlus extends Plus[λ[α => α =>: α]] {
def plus[A](f1: (A =>: A), f2: => (A =>: A)) = self.compose(f1, f2)
}
protected[this] trait ComposeSemigroup[A] extends Semigroup[A =>: A] {
def append(f1: (A =>: A), f2: => (A =>: A)) = self.compose(f1, f2)
}

/** `semigroup`, but universally quantified. */
def plus: Plus[λ[α => α =>: α]] = new ComposePlus {}
/** The endomorphism semigroup, where `append`=`compose`. */
def semigroup[A]: Semigroup[A =>: A] = new ComposeSemigroup[A] {}

trait ComposeLaw {
/** `compose` is associative. */
def associative[A, B, C, D](ab: (A =>: B), bc: (B =>: C), cd: (C =>: D))
(implicit E: Equal[A =>: D]): Boolean = {
val ad1 = compose(cd, compose(bc, ab))
val ad2 = compose(compose(cd, bc), ab)
}
}

def composeLaw = new ComposeLaw {}

////
val composeSyntax = new scalaz.syntax.ComposeSyntax[=>:] { def F = Compose.this }
}

object Compose {
@inline def apply[F[_, _]](implicit F: Compose[F]): Compose[F] = F

////
////
}
```

Other Scala examples (source code examples)

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

 ... this post is sponsored by my books ... #1 New Release! FP Best Seller