python/returns
-
IO & IOResultpython/returns 2022. 9. 4. 22:10
https://returns.readthedocs.io/en/latest/pages/io.html# retry, error recovery 등의 추가 기능을 제공하지 않는 것 같다. 차라리 Result (or ResultE) 를 사용하는 것이 나을 것 같다. ########################################################################### # IO # Some IO never fails, like: getting current date and time, random number, or OS name ########################################################################### import ran..
-
Result & ResultEpython/returns 2022. 9. 4. 21:37
https://returns.readthedocs.io/en/latest/pages/result.html scala Either 와 비슷한듯 error 를 Exception 으로 고정해 scala Try 처럼 사용해도 좋을 듯, ResultE[T] = Result[T, Exception] Result.do 와 pipe 도 알아두자 (flow 대신에 Result.do 를 사용하자?) from typing import Callable from returns.pipeline import flow, pipe from returns.pointfree import bind from returns.result import Result, Success, Failure, ResultE x: ResultE[int] = S..
-
Maybepython/returns 2022. 9. 4. 21:08
https://returns.readthedocs.io/en/latest/pages/maybe.html (scala 의 Option 과 비슷한듯) from returns.maybe import Maybe, Some Maybe.from_value(1) Maybe.from_optional(2) Maybe.from_optional(None) x = Some(2) y = Some(3) z: Maybe = Maybe.empty # map x.map(lambda a: a + 3) # Some(5) # flatMap x.bind(lambda a: Some(a + 3)) # Some(5) # for-comprehension Maybe.do( a + b for a in x for b in y ) # Some(5) # p..