function1.scala

来自「JAVA 语言的函数式编程扩展」· SCALA 代码 · 共 51 行

SCALA
51
字号
/*                     __                                               *\**     ________ ___   / /  ___     Scala API                            ****    / __/ __// _ | / /  / _ |    (c) 2002-2008, LAMP/EPFL             ****  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **** /____/\___/_/ |_/____/_/ | |                                         ****                          |/                                          **\*                                                                      */// $Id: Function1.scala 14670 2008-04-16 14:47:55Z washburn $// generated by genprod on Wed Apr 16 16:46:04 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</code> is a shorthand for the anonymous class definition *    <code>anonfun1</code>: *  </p> *  <pre> *  <b>object</b> Main <b>extends</b> Application { * *    <b>val</b> succ = (x: Int) => x + 1 * *    <b>val</b> anonfun1 = <b>new</b> Function1[Int, Int] { *      <b>def</b> apply(x: Int): Int = x + 1 *    } * *    println(succ(0)) *    println(anonfun1(0)) *  }</pre> */trait Function1[-T1, +R] extends AnyRef {  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)) }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?