3 ms·
Looks like this library is serious. Most of what I see can be written more succinctly using existing Python functionality: 1. Maybe -> Optional[T] 2. Resul
by davidfstr 3y ago
Looks like this library is serious. Most of what I see can be written more succinctly using existing Python functionality:
1. Maybe -> Optional[T]
2. Result -> Union[SuccessT, FailureT]
3. Future, FutureResult -> concurrent.futures.Future[T]
4. IO -> don't use this; none of the standard library I/O supports it
I do appreciate the use of "container" as a term instead of "monad".
I also appreciate the typechecker enhancements being put forward by their custom plugins.
- BerislavLopac 3y agoI believe the recent idiomatic recommendation for the first two is to use the union type expression: 1. T | None 2. SuccessT | FailureT
- epgui 3y agoThis is potentially quite helpful, but would you happen to have a source for that?
- TrickardRixx 3y agoThe Union Type PEP[0] suggests that the "bitwise or" syntax is equivalent, but cleaner than typing.Union [0]: https://docs.python.org/3/library/stdtypes.html#types-union https://docs.python.org/3/library/stdtypes.html#types-union
- epgui 3y agoThanks! I missed that.
- BerislavLopac 3y agoThey're both perfectly valid; but the expression style [0] is shorter and more obvious, especially compared to Optional. Even the documentation for Optional states [1]: Note that this is not the same concept as an optional argument, which is one that has a default. [0] https://docs.python.org/3.11/library/stdtypes.html#types-union https://docs.python.org/3.11/library/stdtypes.html#types-uni... [1] https://docs.python.org/3.11/library/typing.html#typing.Optional https://docs.python.org/3.11/library/typing.html#typing.Opti...
- emblaegh 3y agoNone of these has the functionality that the library offers, i.e. providing an interface to compose functions that consume and produce these types.