filter_map

emmet.builders.utils.filter_map(fn, work, /, *args, work_keys=None, **kwargs)

Apply a function to each item in an iterable, yielding non-None results.

Lazily maps fn over work, passing each item as the first argument along with any additional positional and keyword arguments. Results that are None are excluded.

When work_keys is provided, each item in work is not passed as a positional argument. Instead, the specified keys are extracted from each item (via attribute access or dict lookup) and forwarded to fn as keyword arguments, merged with any extra **kwargs.

Return type:

Iterator[TypeVar(T)]

Parameters:
  • fn (Callable[[...], T])

  • work (Iterable[V])

  • args (Any)

  • work_keys (list[str] | None)

  • kwargs (Any)

Args:

fn: The function to apply to each item in work. work: The iterable of items to process. *args: Additional positional arguments to forward to fn. work_keys: If provided, a list of keys/attributes to extract from

each item in work and pass as keyword arguments to fn.

**kwargs: Additional keyword arguments to forward to fn.

Yields:

Non-None results from applying fn to each item in work.