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

Scala example source code file (Function2Ops.scala)

This example Scala source code file (Function2Ops.scala) is included in the "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, applicative, function2ops, tofunction2ops

The Function2Ops.scala Scala example source code

package scalaz
package syntax
package std

final class Function2Ops[T1, T2, R](val self: (T1, T2) => R) extends AnyVal {
  def flip: (T2, T1) => R = (v2: T2, v1: T1) => self(v1, v2)

  def on[X](f: (R, R) => X, t1: (T1, T1), t2: (T2, T2)): X = f(self(t1._1, t2._1), self(t1._2, t2._2))

  def contramap[TT](f: TT => T1)(implicit ev: T1 =:= T2): (TT, TT) => R = (t1, t2) => self(f(t1), ev(f(t2)))

  def lift[F[_]](implicit F: Applicative[F]): (F[T1], F[T2]) => F[R] = F.lift2(self)

  def byName: (=> T1, => T2) => R = (t1, t2) => self(t1, t2)

trait ToFunction2Ops {
  implicit def ToFunction2Ops[T1, T2, R](f: (T1, T2) => R) = new Function2Ops(f)

Other Scala examples (source code examples)

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

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

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
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.