haldis/app/utils.py

25 lines
515 B
Python
Raw Normal View History

2019-09-10 13:17:35 +00:00
"Script which contains several utils for Haldis"
from typing import Iterable
2019-09-10 13:17:35 +00:00
2019-09-07 23:58:21 +00:00
def euro_string(value: int) -> str:
"""
Convert cents to string formatted euro
"""
return "{}.{:02}".format(*divmod(value, 100))
def first(iterable: Iterable, default=None):
"""
Return first element of iterable
"""
try:
return next(iter(iterable))
except StopIteration:
return default
def ignore_none(iterable: Iterable):
return filter(lambda x: x is not None, iterable)