Molecule<T> constructor

Molecule<T>({
  1. required List<Atom> atoms,
  2. required T computer(
    1. Atom<E>? <E>(
      1. String getAtom
      )
    ),
  3. required String key,
})

Constructor. atoms the Atoms to be used when computing this Molecule's value. computer the function that computes this Molecule's value. key this Molecule's globally unique key.

Returns the newly created Molecule.

Implementation

Molecule(
    {required List<Atom> atoms,
    required T Function(Atom<E>? Function<E>(String getAtom)) computer,
    required String key})
    : _atoms = atoms,
      _computer = computer,
      key = key {
  _atoms.forEach((atom) {
    atom.stateStream.listen((value) {
      _computeValue();
    });
  });

  _computeValue();
}