Think about lazy loop method
Imagine that you have a list of 3 elements. And you are going to use Fold.loop on it.
The first one is Failure(1).
Currently, loop will iterate over all 3 elements. With no breakpoints.
But, Failure(1) is a roadblock for any other logic. We should not iterate over other values.
We need to think about best solutions here. Criteria:
- It should ideally work with any
FailableN - It should be similar to
loopin semantics - It should be possible to use
looporloop_lazilyon the same functions / helpers. In other words, it should be easy to switch from one to another - It should be faster than
loop
Ideas?
This seems to be solving the same problem
- https://docs.rs/itertools/0.5.9/itertools/trait.Itertools.html#method.fold_results, https://docs.rs/itertools/0.9.0/itertools/trait.Itertools.html#method.fold_options -- pretty straightforward and aiming at results and options respectively
- https://docs.rs/itertools/0.5.9/itertools/trait.Itertools.html#method.fold_while -- more general, but requires a function to be aware of calling convention, which is somewhat inconvenient. Can be used as underlying building block when implementing for more specific cases?
@makarchuk yes, that's exactly the same 🙂
We just need to think about the API and implement a single fold_failable in https://github.com/dry-python/returns/blob/master/returns/iterables.py
Do you want to work on it? 🙂
I do, but currently I'm struggling to wrap my head around type signatures you're using. HKT is a concept I've known for a while, but never understood, so I'm stuck at figuring out signature of loop_failable at the moment.
I'm not sure what a signature of Callable should be. It should be something like Result[_UpdatedType, _ErrorType] but that's not flexible enough (only supports Results, which is not the objective here) and I really don't get how FailableN which I presumably need to use, works.
You can start small without any signatures at all.
I really don't get how FailableN which I presumably need to use, works.
It is a common interfaces for all types that can fail, like Result or Maybe or IOResult or FutureResult.
Think of it as a Container with lash method.