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

Scala example source code file (spec-Function1.scala)

This example Scala source code file (spec-Function1.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

a, a, anyref, function1, function1, r, r, t1, t1

The Scala spec-Function1.scala source code

/*                     __                                               *\
**     ________ ___   / /  ___     Scala API                            **
**    / __/ __// _ | / /  / _ |    (c) 2002-2011, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

// generated by genprod on Wed Apr 23 10:06:16 CEST 2008 (with fancy comment) (with extra methods)

package scala


/** <p>
 *    Function with 1 parameters.
 *  </p>
 *  <p>
      In the following example the definition of
 *    <code>succ is a shorthand for the anonymous class definition
 *    <code>anonfun1:
 *  </p>
 *  <pre>
 *  <b>object Main extends App {
 *
 *    <b>val succ = (x: Int) => x + 1
 *
 *    <b>val anonfun1 = new Function1[Int, Int] {
 *      <b>def apply(x: Int): Int = x + 1
 *    }
 *
 *    println(succ(0))
 *    println(anonfun1(0))
 *  }</pre>
 */
trait Function1[@specialized -T1, @specialized +R] extends AnyRef { self =>
  def apply(v1:T1): R
  override def toString() = "<function>"
  
  /** (f compose g)(x) ==  f(g(x))
   */
  def compose[A](g: A => T1): A => R = { x => apply(g(x)) }
  
  /** (f andThen g)(x) ==  g(f(x))
   */
  def andThen[A](g: R => A): T1 => A = { x => g(apply(x)) }

}

Other Scala examples (source code examples)

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