Trait/Object

com.thoughtworks.feature

ImplicitApply

Related Docs: object ImplicitApply | package feature

Permalink

trait ImplicitApply[F] extends Serializable

A dependent type class that invokes F with implicit values as parameters.

Imports

import com.thoughtworks.feature.ImplicitApply.ops._

This will enable the implicitApply method for any functions

Author:

杨博 (Yang Bo) <[email protected]>

F

The function type to be implicitly invoked

Source
ImplicitApply.scala
Examples:
  1. Given a function f that requires an Ordering[Int]

    val f = { x: Ordering[Int] =>
      "OK"
    }

    Then f can implicitly apply as long as its parameter is implicitly available,

    f.implicitApply should be("OK")
  2. ,
  3. Given a function f that requires an call-by-name Ordering[Int]

    def f0(x: => Ordering[Int]) = "OK"
    val f = f0 _

    Then f can implicitly apply as long as its parameter is implicitly available,

    f.implicitApply should be("OK")
Note

You can optionally add an implicit modifier on the function parameter.

val f = { implicit x: Ordering[Int] =>
  "OK"
}
f.implicitApply should be("OK")

It is very useful when you create a curried function.

def g[A] = { (i: A, j: A) => implicit x: Ordering[A] =>
  import x._
  if (i > j) {
    s"$i is greater than $j"
  } else {
    s"$i is not greater than $j"
  }
}
g(1, 2).implicitApply should be("1 is not greater than 2")
Linear Supertypes
Serializable, Serializable, Any
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ImplicitApply
  2. Serializable
  3. Serializable
  4. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type Out

    Permalink

Abstract Value Members

  1. abstract def apply(f: F): Out

    Permalink
  2. abstract def getClass(): Class[_]

    Permalink
    Definition Classes
    Any

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    Any
  3. def +(other: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from ImplicitApply[F] to any2stringadd[ImplicitApply[F]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (ImplicitApply[F], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from ImplicitApply[F] to ArrowAssoc[ImplicitApply[F]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  7. def ensuring(cond: (ImplicitApply[F]) ⇒ Boolean, msg: ⇒ Any): ImplicitApply[F]

    Permalink
    Implicit information
    This member is added by an implicit conversion from ImplicitApply[F] to Ensuring[ImplicitApply[F]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  8. def ensuring(cond: (ImplicitApply[F]) ⇒ Boolean): ImplicitApply[F]

    Permalink
    Implicit information
    This member is added by an implicit conversion from ImplicitApply[F] to Ensuring[ImplicitApply[F]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  9. def ensuring(cond: Boolean, msg: ⇒ Any): ImplicitApply[F]

    Permalink
    Implicit information
    This member is added by an implicit conversion from ImplicitApply[F] to Ensuring[ImplicitApply[F]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  10. def ensuring(cond: Boolean): ImplicitApply[F]

    Permalink
    Implicit information
    This member is added by an implicit conversion from ImplicitApply[F] to Ensuring[ImplicitApply[F]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    Any
  12. def formatted(fmtstr: String): String

    Permalink
    Implicit information
    This member is added by an implicit conversion from ImplicitApply[F] to StringFormat[ImplicitApply[F]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  13. def hashCode(): Int

    Permalink
    Definition Classes
    Any
  14. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  15. def toString(): String

    Permalink
    Definition Classes
    Any
  16. def [B](y: B): (ImplicitApply[F], B)

    Permalink
    Implicit information
    This member is added by an implicit conversion from ImplicitApply[F] to ArrowAssoc[ImplicitApply[F]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from Serializable

Inherited from Serializable

Inherited from Any

Inherited by implicit conversion any2stringadd from ImplicitApply[F] to any2stringadd[ImplicitApply[F]]

Inherited by implicit conversion StringFormat from ImplicitApply[F] to StringFormat[ImplicitApply[F]]

Inherited by implicit conversion Ensuring from ImplicitApply[F] to Ensuring[ImplicitApply[F]]

Inherited by implicit conversion ArrowAssoc from ImplicitApply[F] to ArrowAssoc[ImplicitApply[F]]

Ungrouped