Iteration on Lea instances

Issue #92 resolved
Pierre Denis repo owner created an issue

It is currently not possible to iterate on a Lea instance.

list(my_lea_instance)
# -> LeaError: cannot iterate on a Lea instance
for x in my_lea_instance:

# -> LeaError: cannot iterate on a Lea instance

Also, it is not possible to call len function (raises TypeError exception).

OK... These are prudent options, unless a clear semantic is defined.

Now, since Lea supports slicing, it could be sensible to define iteration so as to yield my_lea_instance[0], my_lea_instance[1], …

Because this is done by building new instances obtained by slicing inner values, this is not meaningful on all Lea instances. This requires that the instance are subscriptable, and has a well-defined length. Two Lea subclasses could meet these requirements:

  • Clea instance, resulting from a joint of N Lea instances: the len and iter functions shall work, the latter simply yielding these N instances;
  • Alea instance: one shall verify that all inner values have same length; if this is the case, the len and iter functions shall work.

Comments (2)

  1. Log in to comment