Packages

trait Function1[-T1, +R] extends AnyRef

A function of 1 parameter.

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

 object Main extends App {
   val succ = (x: Int) => x + 1
   val anonfun1 = new Function1[Int, Int] {
     def apply(x: Int): Int = x + 1
   }
   assert(succ(0) == anonfun1(0))
}

Note that the difference between Function1 and scala.PartialFunction is that the latter can specify inputs which it will not handle.

Self Type
(T1) => R
Annotations
@implicitNotFound()
Source
Function1.scala
Linear Supertypes
Known Subclasses
<:<, =:=, ValueSet, PartialFunction, AbstractMap, AbstractMapView, AbstractSeq, AbstractSet, BitSet, BitSetOps, IndexedSeq, LinearSeq, Map, MapFactoryDefaults, MapOps, KeySet, MapView, Filter, FilterKeys, Id, MapValues, TapEach, Seq, SeqMap, Set, SetOps, SortedMap, SortedMapFactoryDefaults, SortedMapOps, KeySortedSet, SortedSet, SortedSetFactoryDefaults, SortedSetOps, StrictOptimizedMapOps, StrictOptimizedSetOps, StrictOptimizedSortedMapOps, StrictOptimizedSortedSetOps, Map, TrieMap, ::, AbstractMap, AbstractSeq, AbstractSet, ArraySeq, ofBoolean, ofByte, ofChar, ofDouble, ofFloat, ofInt, ofLong, ofRef, ofShort, ofUnit, BitSet, HashMap, HashSet, IndexedSeq, IntMap, LazyList, LinearSeq, List, ListMap, ListSet, Node, LongMap, Map, Map1, Map2, Map3, Map4, WithDefault, MapOps, ImmutableKeySet, Nil, NumericRange, Exclusive, Inclusive, Queue, Range, Exclusive, Inclusive, Seq, SeqMap, Set, Set1, Set2, Set3, Set4, SetOps, SortedMap, WithDefault, SortedMapOps, ImmutableKeySortedSet, SortedSet, SortedSetOps, Cons, Empty, StrictOptimizedMapOps, StrictOptimizedSetOps, StrictOptimizedSortedMapOps, StrictOptimizedSortedSetOps, TreeMap, TreeSeqMap, TreeSet, Vector, VectorMap, WrappedString, AbstractBuffer, AbstractMap, AbstractSeq, AbstractSet, AnyRefMap, ArrayBuffer, ArrayDeque, ArraySeq, ofBoolean, ofByte, ofChar, ofDouble, ofFloat, ofInt, ofLong, ofRef, ofShort, ofUnit, BitSet, Buffer, CollisionProofHashMap, HashMap, HashSet, IndexedBuffer, IndexedSeq, LinkedHashMap, LinkedKeySet, LinkedHashSet, ListBuffer, LongMap, Map, WithDefault, MapOps, Queue, Seq, SeqMap, Set, SetOps, SortedMap, WithDefault, SortedMapOps, SortedSet, SortedSetOps, Stack, StringBuilder, TreeMap, TreeSet, UnrolledBuffer, WeakHashMap, Accumulator, AnyAccumulator, DoubleAccumulator, FromJavaConsumer, FromJavaDoubleConsumer, FromJavaDoubleFunction, FromJavaDoublePredicate, FromJavaDoubleToIntFunction, FromJavaDoubleToLongFunction, FromJavaDoubleUnaryOperator, FromJavaFunction, FromJavaIntConsumer, FromJavaIntFunction, FromJavaIntPredicate, FromJavaIntToDoubleFunction, FromJavaIntToLongFunction, FromJavaIntUnaryOperator, FromJavaLongConsumer, FromJavaLongFunction, FromJavaLongPredicate, FromJavaLongToDoubleFunction, FromJavaLongToIntFunction, FromJavaLongUnaryOperator, FromJavaPredicate, FromJavaToDoubleFunction, FromJavaToIntFunction, FromJavaToLongFunction, FromJavaUnaryOperator, IntAccumulator, LongAccumulator, SystemProperties, DefaultMap, BitSet1, BitSet2, BitSetN, Stream, ListMap, MultiMap, OpenHashMap
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Function1
  2. AnyRef
  3. Any
Implicitly
  1. by UnliftOps
  2. by any2stringadd
  3. by StringFormat
  4. by Ensuring
  5. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Abstract Value Members

  1. abstract def apply(v1: T1): R

    Apply the body of this function to the argument.

    Apply the body of this function to the argument.

    returns

    the result of function application.

Concrete Value Members

  1. def andThen[A](g: (R) => A): (T1) => A

    Composes two instances of Function1 in a new Function1, with this function applied first.

    Composes two instances of Function1 in a new Function1, with this function applied first.

    A

    the result type of function g

    g

    a function R => A

    returns

    a new function f such that f(x) == g(apply(x))

    Annotations
    @unspecialized()
  2. def compose[A](g: (A) => T1): (A) => R

    Composes two instances of Function1 in a new Function1, with this function applied last.

    Composes two instances of Function1 in a new Function1, with this function applied last.

    A

    the type to which function g can be applied

    g

    a function A => T1

    returns

    a new function f such that f(x) == apply(g(x))

    Annotations
    @unspecialized()
  3. def toString(): String

    Creates a String representation of this object.

    Creates a String representation of this object. The default representation is platform dependent. On the java platform it is the concatenation of the class name, "@", and the object's hashcode in hexadecimal.

    returns

    a String representation of the object.

    Definition Classes
    Function1 → AnyRef → Any
  4. def unlift: PartialFunction[T1, B]

    Converts an optional function to a partial function.

    Converts an optional function to a partial function.

    Implicit
    This member is added by an implicit conversion from (T1) => R toUnliftOps[T1, B] performed by method UnliftOps in scala.Function1.This conversion will take place only if R is a subclass of Option[B] (R <: Option[B]).
    Definition Classes
    UnliftOps
    Example:
    1. Unlike Function.unlift, this UnliftOps.unlift method can be used in extractors.

      val of: Int => Option[String] = { i =>
        if (i == 2) {
          Some("matched by an optional function")
        } else {
          None
        }
      }
      
      util.Random.nextInt(4) match {
        case of.unlift(m) => // Convert an optional function to a pattern
          println(m)
        case _ =>
          println("Not matched")
      }