Functoid

izumi.distage.model.providers.Functoid
See theFunctoid companion object
final case class Functoid[+A](get: Provider) extends AbstractFunctoid[A, Functoid]

A function that receives its arguments from DI object graph, including named instances via izumi.distage.model.definition.Id annotation.

The following syntaxes are supported by extractor macro:

Inline lambda:

 make[Unit].from {
   i: Int @Id("special") => ()
 }

Method reference:

 def constructor(@Id("special") i: Int): Unit = ()

 make[Unit].from(constructor _)

 make[Unit].from(constructor(_))

Function value with an annotated signature:

 val constructor: (Int @Id("special"), String @Id("special")) => Unit = (_, _) => ()

 make[Unit].from(constructor)

Using intermediate vals will lose annotations when converting a method into a function value, Prefer passing inline lambdas such as { x => y } or method references such as (method _) or (method(_)).:

 def constructorMethod(@Id("special") i: Int): Unit = ()

 val constructor = constructorMethod _

 make[Unit].from(constructor) // SURPRISE: Will summon regular Int, not a "special" Int from DI object graph
 make[Unit].from(constructorMethod _) // Will work correctly: summon "special" Int

Prefer annotating parameter types, not parameters: class X(i: Int @Id("special")) { ... }

 final case class X(i: Int @Id("special"))

 make[X].from(X.apply _) // summons special Int

Functoid forms an applicative functor via its izumi.distage.model.providers.Functoid.pure & izumi.distage.model.providers.AbstractFunctoid.map2 methods

Attributes

See also

Functoid is based on the Magnet Pattern: http://spray.io/blog/2012-12-13-the-magnet-pattern/

Essentially Functoid is a function-like entity with additional properties, so it's funny name is reasonable enough: https://en.wiktionary.org/wiki/-oid#English

Note

javax.inject.Named annotation is also supported

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Inherited methods

def addDependencies(keys: Iterable[DIKey]): Functoid[A]

Attributes

Inherited from:
AbstractFunctoid
def addDependency(key: DIKey): Functoid[A]

Attributes

Inherited from:
AbstractFunctoid
def addDependency[B : Tag](name: Identifier): Functoid[A]

Attributes

Inherited from:
AbstractFunctoid
def addDependency[B : Tag]: Functoid[A]

Add B as an unused dependency of this Functoid

Add B as an unused dependency of this Functoid

Attributes

Inherited from:
AbstractFunctoid

Add an @Id(name) annotation to all unannotated parameters

Add an @Id(name) annotation to all unannotated parameters

Attributes

Inherited from:
AbstractFunctoid
def annotateParameter[P : Tag](name: Identifier): Functoid[A]

Add an @Id annotation to an unannotated parameter P, e.g. for .annotateParameterP, transform lambda (p: P) => x(p) into (p: P @Id("my-id")) => x(p)

Add an @Id annotation to an unannotated parameter P, e.g. for .annotateParameterP, transform lambda (p: P) => x(p) into (p: P @Id("my-id")) => x(p)

Attributes

Throws
ParameterNotFoundForAnnotation

if there's no unannotated parameter p: P in functoid

Inherited from:
AbstractFunctoid

Add an @Id annotation to an unannotated parameter P, e.g. for .annotateParameterP, transform lambda (p: P) => x(p) into (p: P @Id("my-id")) => x(p)

Add an @Id annotation to an unannotated parameter P, e.g. for .annotateParameterP, transform lambda (p: P) => x(p) into (p: P @Id("my-id")) => x(p)

Does nothing if there's no unannotated parameter p: P in functoid

Attributes

Inherited from:
AbstractFunctoid
def annotateParameterWhen(name: Identifier)(predicate: BasicKey => Boolean): Functoid[A]

Add an @Id(name) annotation to all parameters matching predicate

Add an @Id(name) annotation to all parameters matching predicate

Attributes

Inherited from:
AbstractFunctoid
def ap[B, C](that: Functoid[B])(implicit ev: A <:< (B => C), tag: Tag[C]): Functoid[C]

Apply a function produced by this Functoid to the argument produced by that Functoid.

Apply a function produced by this Functoid to the argument produced by that Functoid.

Same as

 this.map2(that)((f, a) => f(a))

Attributes

Inherited from:
AbstractFunctoid
def flatAp[B : Tag](that: Functoid[A => B]): Functoid[B]

Applicative's ap method - can be used to chain transformations like flatMap.

Applicative's ap method - can be used to chain transformations like flatMap.

Apply a function produced by that Functoid to the value produced by this Functoid.

Same as

 this.map2(that)((a, f) => f(a))

Attributes

Inherited from:
AbstractFunctoid
def map[B : Tag](f: A => B): Functoid[B]

Attributes

Inherited from:
AbstractFunctoid
def map2[B, C : Tag](that: Functoid[B])(f: (A, B) => C): Functoid[C]

Attributes

Inherited from:
AbstractFunctoid
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
def zip[B](that: Functoid[B]): Functoid[(A, B)]

Attributes

Inherited from:
AbstractFunctoid