dynamic<Param, Return> method
Allows you to more easily construct dynamic capsules.
Dynamic capsules are in contrast to static capsules, which you can think of as just regular capsules ("static" because there is only ever one instantiation per CapsuleContainer).
Dynamic capsules allow you to create a parameterized capsule; i.e., a capsule that also takes in some argument when built. To pass in more than one argument, use a record as the argument.
Warning
Dynamic capsule arguments must correctly implement hashCode and ==.
Internally, this side effect is essentially just a Map wrapper.
Warning
Dynamic capsules are often not what you need.
Typically, you should use factories and/or scoped state instead.
The valid uses for dynamic capsules are:
- Incremental computation
- Dynamic programming/recursive capsules
- Exceptionally odd one-offs (often better solved via a refactor)
If what you are trying to do doesn't fit into one of the above categories, do not use dynamic. Instead, write your code in a different way.
Implementation
DynamicOrchestrator<Param, Return> dynamic<Param, Return>(
Return Function(CapsuleHandle, Param) dyn,
) {
return use.lazyValue(() => DynamicOrchestrator._(dyn));
}