lookupDependencyWithNoEnvOrHasAny function Null safety

DependencyConfig? lookupDependencyWithNoEnvOrHasAny(
  1. InjectedDependency iDep,
  2. Set<DependencyConfig> allDeps,
  3. List<String> envs
)

Implementation

DependencyConfig? lookupDependencyWithNoEnvOrHasAny(
    InjectedDependency iDep, Set<DependencyConfig> allDeps, List<String> envs) {
  try {
    return allDeps.firstWhere(
      (d) =>
          d.type == iDep.type &&
          d.instanceName == iDep.instanceName &&
          (d.environments.isEmpty ||
              envs.isEmpty ||
              d.environments.any(
                (e) => envs.contains(e),
              )),
    );
  } on StateError {}
  return null;
}