amaranth/nmigen/tools.py

23 lines
335 B
Python
Raw Normal View History

2018-12-11 13:50:56 -07:00
from collections import Iterable
__all__ = ["flatten", "union"]
def flatten(i):
for e in i:
if isinstance(e, Iterable):
yield from flatten(e)
else:
yield e
def union(i):
r = None
for e in i:
if r is None:
r = e
else:
r |= e
return r