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.htmlscala Either 와 비슷한듯error 를 Exception 으로 고정해 scala Try 처럼 사용해도 좋을 듯, ResultE[T] = Result[T, Exception]Result.do 와 pipe 도 알아두자 (flow 대신에 Result.do 를 사용하자?) from typing import Callablefrom returns.pipeline import flow, pipefrom returns.pointfree import bindfrom returns.result import Result, Success, Failure, ResultEx: ResultE[int] = Success(..
-
Maybepython/returns 2022. 9. 4. 21:08
https://returns.readthedocs.io/en/latest/pages/maybe.html(scala 의 Option 과 비슷한듯)from returns.maybe import Maybe, Some, NothingMaybe.from_value(1)Maybe.from_optional(2)Maybe.from_optional(None)x = Some(2)y = Some(3)z: Maybe = Nothing# z: Maybe = Maybe.empty# mapx.map(lambda a: a + 3) # Some(5)# flatMapx.bind(lambda a: Some(a + 3)) # Some(5)# for-comprehensionMaybe.do( a + b for a in x ..