Breeds a neuron of the given type, wiring each synapse to a value with the same name and an assignment-compatible return type or to a function with the same name and an assignment-compatible return type which accepts the given type or any supertype as its sole parameter.
Breeds a neuron of the given type, wiring each synapse to a value with the same name and an assignment-compatible return type or to a function with the same name and an assignment-compatible return type which accepts the given type or any supertype as its sole parameter. Example:
@Neuron trait Foo[A] { def a: A def b: A def c: A } object Main extends App { val a = "World" def b(neuron: Foo[String]) = "Hello, " + neuron.a val c = (neuron: Foo[String]) => neuron.b + "!" val foo = wire[Foo[String]] println(foo.c) }
When run, Main
will print Hello, World!
to standard output.
When calling wire[Foo[String]]
, the type parameter of Foo
is set to String
, so the synapses a
,
b
and c
each return a String
.
The synapses are bound to their dependencies as follows:
+ The synapse a
is bound to the value a
of type String
.
+ The synapse b
is bound to the function definition b
which accepts a parameter of the type Foo[String]
.
+ The synapse c
is bound to the function value c
which again accepts a parameter of the type Foo[String]
.
Finally, when calling foo.c
, the function value c
will call the function definition b
which in turn will
call the value a
to compute "Hello, World!"
.
Neuron DI 5.0 (renamed from neuron
, which was introduced in Neuron DI 4.2)