Refactoring

This commit is contained in:
elvis
2025-06-16 14:46:04 +02:00
parent 0975d593f8
commit b94afa3f52
8 changed files with 359 additions and 263 deletions

View File

@ -10,7 +10,7 @@ use super::structure::{RSset, RSreaction};
/// Computes the result of a single reaction (if enabled returns the products)
/// otherwise returns None.
pub fn compute_step<'a>(current_state: &RSset<'a>, reaction: &'a RSreaction<'a>) -> Option<&'a RSset<'a>> {
pub fn compute_step<'a>(current_state: &'a RSset, reaction: &'a RSreaction) -> Option<&'a RSset> {
if reaction.enabled(current_state) {
Some(reaction.products())
} else {
@ -20,6 +20,6 @@ pub fn compute_step<'a>(current_state: &RSset<'a>, reaction: &'a RSreaction<'a>)
/// Computes the result of a series of reactions. Returns the union of all
/// products.
pub fn compute_all<'a>(current_state: &RSset<'a>, reactions: Vec<&'a RSreaction<'a>>) -> RSset<'a> {
pub fn compute_all<'a>(current_state: &'a RSset, reactions: Vec<&'a RSreaction>) -> RSset {
reactions.iter().fold(RSset::new(), |acc, r| acc.union_option(compute_step(current_state, r)))
}