Skip to content

on_error Functionality #65

Closed
Closed

Description

@EntilZha

The functionality from https://github.com/jagill/python-chainz#errors would be useful for certain use cases. Wrapping this into Lineage seems like a fairly clean way to accomplish this.

On a side note, this might be a good time to look at making the exceptions raised from evaluating an incorrect user function in a PyFunctional pipeline cleaner. Currently, there is quite a bit of noise when its is very unlikely the core issue is coming from PyFunctional.

Activity

  1. self-assigned this
    on Apr 4, 2016
  2. added this to the 1.0.0 milestone on Apr 4, 2016
  3. changed the title [-]`on_error` Functionality[/-] [+]on_error Functionality[/+] on Apr 4, 2016
  4. modified the milestones: 0.7.0, 1.0.0 on May 6, 2016
  5. EntilZha commented on May 7, 2016

    @EntilZha
    OwnerAuthor

    Gave a good shot at implementing this and don't think that the changes to make it happen would be worth it.

    Consider this code block:

    def f(x):
        if x == 1:
            raise ValueError("Not 1!")
        return x * 2
    seq.range(4).map(f)

    In order to handle this, its not enough to wrap the code that executes the sequence, it will still error out. In order to catch that exception you either need to catch it where next is called, wrap f when it is passed through to map, or use a yield statement like done here https://github.com/jagill/python-chainz/blob/master/chainz/chain.py#L52

    The first one is obviously not an option since thats user code vs library code. There are two possible problematic implementations:

    1. You could wrap f then pass it through. The issue is that there would need to be checks on all methods that accept a function if on_error would work as expected. This is a lot of methods that would have to be changed to support this single one which I don't think adds much value (more on this later)
    2. The second one is clear how to do for map and other functions that operate at a single "level". For example, flat_map since tricky since the results have to get concatenated. The generalization is that implementing this would be method specific so quite a bit of work.

    Lastly, I don't think it brings much value for all the effort needed. It would be much easier for user code to handle the exception explicitly. This could be easy to do using flat_map very easily. If there is an error output an empty list, otherwise a tuple of one element (yay monads). It would also be easy to do a map then filter.

    I had hoped the implementation wouldn't require so much code change and would be easy, but wasn't to be. I am open to other ideas, but closing issue for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions