Comments (1)
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:
- 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 ifon_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) - 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.
from pyfunctional.
Related Issues (20)
- dict usage HOT 2
- pseq speed HOT 2
- pyfunctional is incompatible with multiprocess because dill HOT 7
- any kind of join with different key name HOT 1
- Could I use the index in the map function HOT 1
- Latest version has pandas/numpy as requirements HOT 2
- for_each doesn't return the original sequence but returns None HOT 8
- Unexpected behaviour on chain with .drop_right HOT 2
- Unexpected Sequence wrapping from grouped HOT 7
- Empty sequence HOT 6
- Tuple argument unpacking functionality HOT 4
- lazy_parallellize having trouble with function context? HOT 3
- "peek" functionality HOT 1
- seq() converts pandas DataFrame into Sequence HOT 8
- Cache to file and auto-load from cache HOT 4
- [Question] VSCode language server doesn't see the pyfunctional package HOT 3
- Thank you! HOT 1
- More dictionary/tuple list helpers HOT 5
- the installation of the PyFunctional package has failed due to a missing item in the package archive. HOT 3
- Old link to documentation in pypi HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyfunctional.