“要么”和“也许”数据结构
either的Python项目详细描述
https://github.com/kennknowles/python-either
这个库为python提供了两个基本的几乎微不足道的数据结构:
- Either also known as “coproduct”, “sum type”, “variant”, “tagged union”, “disjoint union”, etc: A value that comes from one of two sets
- Maybe also known as “option” or “Either Nothing”: A value that may be missing. (Python has “None” but it does not compose)
每行大约10行,大部分是样板文件,但现在它们在一个库中的一个位置。
进一步阅读:
如果您不熟悉这些概念,下面是一些来自网络的阅读资料:
或者:
- [Tagged union (Wikipedia)](http://en.wikipedia.org/wiki/Tagged_union)
- [Either (Scala)](http://www.scala-lang.org/api/current/scala/Either.html)
- [Boost.Variant (C++)](http://www.boost.org/doc/libs/1_50_0/doc/html/variant.html)
- [Data.Either (Haskell)](http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Either.html)
- [std.variant (D)](http://dlang.org/phobos/std_variant.html)
可能:
- [Option (Scala)](http://www.scala-lang.org/api/current/scala/Option.html)
- [Maybe (Java)](https://github.com/npryce/maybe-java)
- [Maybe pattern (Python recipe)](http://code.activestate.com/recipes/577248-maybe-pattern/)
- [Data.Maybe (Haskell)](http://www.haskell.org/ghc/docs/latest/html/libraries/base/Data-Maybe.html)
- [Maybe (Ruby)](https://github.com/bhb/maybe)
贡献者
- [Kenn Knowles](https://github.com/kennknowles) ([@kennknowles](https://twitter.com/KennKnowles))
版权和许可
版权所有2012-Kenneth Knowles
根据apache许可证2.0版(以下简称“许可证”)授权; 除非符合许可证,否则您不能使用此文件。 您可以在
http://www.apache.org/licenses/LICENSE-2.0
除非适用法律要求或书面同意,否则软件 根据许可证分发是按“原样”分发的, 无任何明示或默示的保证或条件。 有关管理权限的特定语言和 许可下的限制。