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

Scala example source code file (Cozip.scala)

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

cozip

The Cozip.scala Scala example source code

package scalaz

////
/**
 *
 */
////
trait Cozip[F[_]]  { self =>
  ////
  def cozip[A, B](x: F[A \/ B]): (F[A] \/ F[B])

  // derived functions
  def cozip3[A, B, C](x: F[A \/ (B \/ C)]): (F[A] \/ (F[B] \/ F[C])) =
    cozip(x).map(cozip(_))

  def cozip4[A, B, C, D](x: F[A \/ (B \/ (C \/ D))]): (F[A] \/ (F[B] \/ (F[C] \/ F[D]))) =
    cozip(x).map(cozip(_) map (cozip(_)))

  def cozip5[A, B, C, D, E](x: F[(A \/ (B \/ (C \/ (D \/ E))))]): (F[A] \/ (F[B] \/ (F[C] \/ (F[D] \/ F[E])))) =
    cozip(x).map(cozip(_) map (cozip(_) map (cozip(_))))

  def cozip6[A, B, C, D, E, G](x: F[(A \/ (B \/ (C \/ (D \/ (E \/ G)))))]): (F[A] \/ (F[B] \/ (F[C] \/ (F[D] \/ (F[E] \/ F[G]))))) =
    cozip(x).map(cozip(_) map (cozip(_) map (cozip(_) map (cozip(_)))))

  def cozip7[A, B, C, D, E, G, H](x: F[(A \/ (B \/ (C \/ (D \/ (E \/ (G \/ H))))))]): (F[A] \/ (F[B] \/ (F[C] \/ (F[D] \/ (F[E] \/ (F[G] \/ F[H])))))) =
    cozip(x).map(cozip(_) map (cozip(_) map (cozip(_) map (cozip(_) map(cozip(_))))))

  ////
  val cozipSyntax = new scalaz.syntax.CozipSyntax[F] { def F = Cozip.this }
}

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

  ////
  def cofzip[F[_], A, B](x: F[A \/ B])(implicit F: Cozip[F]): (F[A] \/ F[B]) = F.cozip(x)
  def cofzip3[F[_], A, B, C](x: F[A \/ (B \/ C)])(implicit F: Cozip[F]): (F[A] \/ (F[B] \/ F[C])) = F.cozip3(x)
  def cofzip4[F[_], A, B, C, D](x: F[A \/ (B \/ (C \/ D))])(implicit F: Cozip[F]): (F[A] \/ (F[B] \/ (F[C] \/ F[D]))) = F.cozip4(x)
  def cofzip5[F[_], A, B, C, D, E](x: F[(A \/ (B \/ (C \/ (D \/ E))))])(implicit F: Cozip[F]): (F[A] \/ (F[B] \/ (F[C] \/ (F[D] \/ F[E])))) = F.cozip5(x)
  def cofzip6[F[_], A, B, C, D, E, G](x: F[(A \/ (B \/ (C \/ (D \/ (E \/ G)))))])(implicit F: Cozip[F]): (F[A] \/ (F[B] \/ (F[C] \/ (F[D] \/ (F[E] \/ F[G]))))) = F.cozip6(x)
  def cofzip7[F[_], A, B, C, D, E, G, H](x: F[(A \/ (B \/ (C \/ (D \/ (E \/ (G \/ H))))))])(implicit F: Cozip[F]): (F[A] \/ (F[B] \/ (F[C] \/ (F[D] \/ (F[E] \/ (F[G] \/ F[H])))))) = F.cozip7(x)
  ////
}

Other Scala examples (source code examples)

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