getClientByEmail<T> function

T getClientByEmail<T>(
  1. List<T> clients,
  2. String? email,
  3. String inboundTag
)

Find client by email in provided clients list or throw a clear error. Find client by email in provided clients list or throw a clear error.

This method is generic and will return the found element cast to T.

Implementation

T getClientByEmail<T>(List<T> clients, String? email, String inboundTag) {
  return clients.cast<T>().firstWhere(
    (c) => ((c as dynamic).email ?? '') == email,
    orElse: () => throw ArgumentError(
      'Client for Email = $email not found in inbound $inboundTag',
    ),
  );
}