[Python-ideas] A real life example of "given"
Adam Bartoš
drekin at gmail.com
Wed May 30 18:36:45 EDT 2018
A side comment:
> potential_updates = {
> y: potential_update
> for x in need_initialization_nodes
> for y in [x, *x.synthetic_inputs()]
> given potential_update = command.create_potential_update(y)
> if potential_update is not None}
Probably, I would write
@make_dict
def potential_updates():
for x in need_initialization_nodes:
for y in [x, *x.synthetic_inputs()]:
potential_update = command.create_potential_update(y)
if potential_update is not None:
yield y, potential_update
If such pattern covered a lot of examples, even some syntax sugar could be
added. For example:
foo[0].potential_updates = dict(_) from:
for x in need_initialization_nodes:
for y in [x, *x.synthetic_inputs()]:
potential_update = command.create_potential_update(y)
if potential_update is not None:
yield y, potential_update
where
<statement> from:
<suite>
would be equivalent to
def _():
<suite>
_ = _()
<statement>
Best regards,
Adam Bartoš
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180531/5ef9af51/attachment-0001.html>
More information about the Python-ideas
mailing list