scala

trait Function1

[source: scala/Function1.scala]

trait Function1[-T1, +R]
extends AnyRef

Function with 1 parameters.

In the following example the definition of succ is a shorthand for the anonymous class definition anonfun1:

  object Main extends Application {

    val succ = (x: Int) => x + 1

    val anonfun1 = new Function1[Int, Int] {
      def apply(x: Int): Int = x + 1
    }

    println(succ(0))
    println(anonfun1(0))
  }
Direct Known Subclasses:
Apply0, PartialFunction, StringBuilder, UninitializedFieldError, Set, Index, pilib.Chan, DocGroup, DocText, Parsers.Parser, Number, Ident, Str, Parsers.Parser, Parsers.UnitParser, Comment, EntityRef, Group, MalformedAttributeException, PCData, Text, Unparsed, MIXED, ELEMENTS, IntDef, PEReference, ExtDef, ElementValidator, SystemID, ValidationException, FatalError, Index, EvText, EvEntityRef, EvComment, BasicTransformer, ActionEvent, BackgroundChanged, ButtonClicked, CaretUpdate, ComponentHidden, ComponentShown, ComponentResized, ComponentMoved, EditDone, FontChanged, ForegroundChanged, SelectionChanged, TableResized, TableChanged, TableStructureChanged, ValueChanged, WindowActivated, WindowClosed, WindowClosing, WindowDeactivated, WindowDeiconified, WindowIconified, WindowOpened

Method Summary
def andThen [A](g : (R) => A) : (T1) => A
(f andThen g)(x) == g(f(x))
abstract def apply (v1 : T1) : R
def compose [A](g : (A) => T1) : (A) => R
(f compose g)(x) == f(g(x))
override def toString : java.lang.String
Returns a string representation of the object.
Methods inherited from AnyRef
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
abstract def apply(v1 : T1) : R

override def toString : java.lang.String
Returns a string representation of the object.

The default representation is platform dependent.

Returns
a string representation of the object.


def compose[A](g : (A) => T1) : (A) => R
(f compose g)(x) == f(g(x))

def andThen[A](g : (R) => A) : (T1) => A
(f andThen g)(x) == g(f(x))