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 Thumbnailator库将图像转换为cmyk   Java反射从目录中的类运行测试   JavaEclipseJDT编译器说方法未定义,但EclipseIDE没有   重构如何重构一行重复的java代码   java Eclipse:使用删除线文本呈现自定义注释   java问题与ArrayList复制数据   java如何在swagger中传递访问令牌?   使用另一个java文件运行java文件时出错   java为什么谷歌云存储生成的上传链接在成功上传后不会失效?   java将我的客户端PC重定向到默认登录页面   java hibernate c3p0配置mysql问题   java和java之间的区别。尼奥。文件文件和java。伊奥。文件   列出java循环并向映射中添加值   java为什么OJ报告这段代码的运行时错误?