Is there a Python equivalent for Scala's Option or Either?

前端 未结 8 1549
忘掉有多难
忘掉有多难 2021-02-05 01:26

I really enjoy using the Option and Either monads in Scala. Are there any equivalent for these things in Python? If there aren\'t, then what is the pythonic way of handling erro

8条回答
  •  有刺的猬
    2021-02-05 01:34

    Natively, Python has a Literal Type Optional but it's not the same. Alternatively this is a representation of the Either data type for python 3.

    https://gist.github.com/MatteoGuadrini/98e79a9ab2bd6ae5badc41df89cfe338

提交回复
热议问题