iodevs / pyresult Goto Github PK
View Code? Open in Web Editor NEWA Result pattern for python
License: Other
A Result pattern for python
License: Other
Ok & Ok = Ok
Ok & Error = Error
Error & Ok = Error
Error & Error = Error
Ok | Ok = Ok
Ok | Error = Ok
Error | Ok = Ok
Error | Error = Error
When list contains at least one Error, then product result is Error.
When list contains at least one Ok, then sum product is Ok.
When function in and_then
operator raise excpetion, then and_then
function fail with exception, instead error result.
from pyresult import and_then, ok
def raise_exception(val):
raise Exception()
and_then(raise_exception, ok(1))
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-46-f0756160f235> in <module>()
----> 1 and_then(raise_exception, ok(1))
/usr/local/opt/pyenv/versions/3.6.2/envs/pydecoder/lib/python3.6/site-packages/toolz/functoolz.py in __call__(self, *args, **kwargs)
281 def __call__(self, *args, **kwargs):
282 try:
--> 283 return self._partial(*args, **kwargs)
284 except TypeError as exc:
285 if self._should_curry(args, kwargs, exc):
/usr/local/opt/pyenv/versions/3.6.2/envs/pydecoder/lib/python3.6/site-packages/pyresult/operators.py in and_then(func, res)
40 '''
41 res = result(res)
---> 42 return result(func(res.value)) if is_ok(res) else res
43
44
<ipython-input-43-6bead73ba782> in raise_exception(val)
1 def raise_exception(val):
----> 2 raise Exception()
Look at iodevs/pydecoder#32
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.