python的联合类型

uniontypes的Python项目详细描述


`` union type 0.1``
>





build status


python的union类型。





这些语言出现在haskell(``任`````)和
scala(``union``或````````````````````````````````````````````````````````````````等其他语言中。





>这扩展~~~~~~~~~~~~~~~~~~~~~~
…代码块::python

>;>;来自uniontypes import union
>;>;u=union[list,tuple,str]
>;>;u
<;class'uniontypes.union[list,tuple,str]>;

密码块::python

>gt>gt>u([1,2,2,3])
union[list,tuple,str][list][1,2,2,3]
>gt>gt>u((1,2,2,3))
union[list,tuple,str][list,tuple,str][tuple]>u((1,2,3)
>gt>u('123')
>union[list,tuple,str][str list,tuple,str][list,tuple,str[list,tuple,str][list,tuple,str 1,2,3]>u((1,2,2,3)
>gt>gt>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
…代码块::python

>;>;u[列表]
<;类'uniontypes.union[列表,元组,str][list]'>;
>;>;u[元组]
<;类'uniontypes.union[列表,元组,str][tuple]'>;
>;u[str]
<;类'uniontypes.union[列表,元组,str][str str]>;

代码块::python

>;>;IsInstance(u([1,2,3]),u)
true
>;>;IsInstance(u([1,2,3]),u[list])
true
>;>;IsInstance(u([1,2,3]),(u[元组],u[str])
false

代码块::python

>>from uniontypes import option
>;>;oit=option[int]
>;>;oit
<;class'uniontypes.option[int]>;
>;>;oit(1)
option[int]1
>;>;oit(none)
nothing
>;>;oint(none)是oint。nothing
true



。|构建状态图像::https://travis-ci.org/llllllllll/uniontypes.svg?branch=master
:目标:https://travis-ci.org/llllllllll/uniontypes

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java搜索文本中的字符串模式   SecurityManager引发异常的java Mockito模拟   java(仅限Netbeans)未找到适合jdbc的驱动程序:mysql://localhost   java计算给定字符串所有前缀的哈希值的子字符串的哈希值   java如何避免每次访问REST认证API以使用实际服务   用于HTML的java Jsoup选择器组合   可以复制或引用的java构造函数   Java中的HashMap。搞砸containsKey返回意外值   java数组平均值计算   java是检查字符串是否包含特定字符的最有效方法   java反序列化对象类已更改   java典型的EJB3/JPA/JSF中的事务范围是什么?   Install4j的java错误代码20   java:compileJava在本地项目()依赖项上的多模块项目上持续失败“错误:包x.y.z不存在”   java有一种生成Suppression的方法。现有代码库中checkstyle的xml文件?