Packages

final class Caller[+A] extends AnyVal

An implicit value that points to the function caller.

Usage

libraryDependencies += "com.thoughtworks.feature" %% "caller" % "latest.release"
Getting the caller for logging or something
object Foo{
  def log()(implicit caller: Caller[Any]) = {
    println(caller.value)
  }
}
object Bar{
  Foo.log() // Bar
}
Restricting who you can be called from
class IKnowWhatImDoing
object Foo{
  def runDangerous()(implicit caller: Caller[IKnowWhatImDoing]) = {
    println(caller.value)
  }
}
object Bar {
  Foo.runDangerous() // compile error
}
object Bar2 extends IKnowWhatImDoing{
  Foo.runDangerous() // ok, prints Bar2
}
Getting calling class or classloader, e.g. for loading resources, without needing to worry about properly setting up and tearing down the Context ClassLoader
object Foo{
  def getResource(path: String)(implicit caller: Caller[_]) = {
    caller.value.getClass.getClassLoader.getResourceAsStream(path)
  }
}
object Bar{
  Foo.getResource("/thing/file.txt") // loads resource from `Bar`s classloader, always
}
Authors:

Li Haoyi

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

Source
Caller.scala
Linear Supertypes
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Caller
  2. AnyVal
  3. 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

Instance Constructors

  1. new Caller(value: A)

    value

    The caller instance

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from Caller[A] to any2stringadd[Caller[A]] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Caller[A], B)
    Implicit
    This member is added by an implicit conversion from Caller[A] to ArrowAssoc[Caller[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def ensuring(cond: (Caller[A]) ⇒ Boolean, msg: ⇒ Any): Caller[A]
    Implicit
    This member is added by an implicit conversion from Caller[A] to Ensuring[Caller[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  8. def ensuring(cond: (Caller[A]) ⇒ Boolean): Caller[A]
    Implicit
    This member is added by an implicit conversion from Caller[A] to Ensuring[Caller[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  9. def ensuring(cond: Boolean, msg: ⇒ Any): Caller[A]
    Implicit
    This member is added by an implicit conversion from Caller[A] to Ensuring[Caller[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  10. def ensuring(cond: Boolean): Caller[A]
    Implicit
    This member is added by an implicit conversion from Caller[A] to Ensuring[Caller[A]] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from Caller[A] to StringFormat[Caller[A]] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  12. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  13. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  14. def toString(): String
    Definition Classes
    Any
  15. val value: A
  16. def [B](y: B): (Caller[A], B)
    Implicit
    This member is added by an implicit conversion from Caller[A] to ArrowAssoc[Caller[A]] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from AnyVal

Inherited from Any

Inherited by implicit conversion any2stringadd from Caller[A] to any2stringadd[Caller[A]]

Inherited by implicit conversion StringFormat from Caller[A] to StringFormat[Caller[A]]

Inherited by implicit conversion Ensuring from Caller[A] to Ensuring[Caller[A]]

Inherited by implicit conversion ArrowAssoc from Caller[A] to ArrowAssoc[Caller[A]]

Ungrouped