咖喱功能图案贴片

masala的Python项目详细描述


生成状态

大师级

https://travis-ci.org/hachibeeDI/masala.svg?branch=master

安装

$ pip install masala

示例

咖喱

>>>from__future__import(print_function,division,absolute_import,unicode_literals,)>>>frommasalaimportCurryContainerascc>>>cur=cc(lambdaa,b,c:[a,b,c])>>>cur=cur<<'aaa'<<'bbb'>>>cur('ccc')['aaa','bbb','ccc']>>>cur=cc(lambdaa,b='hogeeee',c='foooo':[a,b,c])>>>cur=cur<<'a'<<('c','c')>>>cur('b')['a','b','c']>>>frommasalaimportcurried>>>@curried...defsum5(a,b,c,d,e):...returna+b+c+d+e...>>>sum0=sum5<<1<<2<<3<<4<<5>>>assertsum0()==sum5(1,2,3,4,5)

短手

λ

>>>frommasalaimportlambdas_>>>frommasala.datatypeimportEither>>>Either.right('hachi')>>_.title()'Hachi'>>>replacer=_.replace(_,_)>>>replacer('hachi','chi','chiboee')'hachiboee'>>>list(map(_+2,range(3)))[2,3,4]>>>fromsix.movesimportreduce>>>reduce(_+_,range(5))10

方法链接
>>>frommasalaimportBuilderAllowsMethodChainingas__>>>Either.right('hachi')>>__.title().replace('i','U').replace('c','z')'HazhU'>>>foolambda=__.title().replace('i','U').replace('c','z')>>>foolambda('hachi')'HazhU'>>>Either.right(4)>>((__+4)*'py'.title())'PyPyPyPyPyPyPyPy'>>>(__+1+2+3+4+5)(0)15>>>(__+1+2+3+4+5).apply__(0)15

列表处理

>>>frommasalaimport(applyasa,lambdas_,)>>>frommasala.datatypeimportStream>>># extends linq like methods to Stream.>>># but I reccomend to use itertools extention is also prepared as `from masala.datatype.stream import itertools_ext`>>>frommasala.datatype.streamimportlinq_ext>>>Stream([1,2,3]).select(_*2).to_list()[2,4,6]>>># support lazy evaluation>>>Stream([1,2,3]).select(_*2)# doctest:+ELLIPSISStream:<<function...>>>Stream(range(0,15)).select(_+1).where(__%2==0).to_list()[2,4,6,8,10,12,14]>>>Stream(range(0,100)).select(_*2).where(_>1000).first()# doctest:+ELLIPSISEmpty:<None>reason=><class'masala.datatype.stream.error.NoContentStreamError'>:>>>Stream(range(0,100)).select(_*2).any(_>1000)False>>>Stream(111111).select(_*2).to_list()Empty:<None>reason=><class'masala.datatype.stream.error.NotIterableError'>: 'int' object is not iterable>>># you can extend the method by yourself>>>frommasala.datatype.streamimportdispatch_stream>>>@dispatch_stream...defmy_select(xs,x_to_y):...forxinxs:...yieldx_to_y(x)>>>Stream([1,2,3]).my_select(_*2).to_list()[2,4,6]>>>frommasala.datatype.streamimportdelete_dispatchedmethods>>># you can clean extentions.>>>delete_dispatchedmethods(['my_select'])>>># other cases>>>twicer=Stream().select(_*2)>>>twiced=twicer<<[1,2,3]>>>list(twiced)[2,4,6]>>>twiced2=twicer<<[2,3,4]>>>list(twiced2)[4,6,8]>>>delete_dispatchedmethods(linq_ext.__all__)

模式匹配

>>>frommasalaimportMatch>>>match=Match(10)>>>ifmatch.when(1):...print('boo')...elifmatch.when(10):...print('yieeeee')yieeeee>>>frommasalaimportWildcardas_>>>match=Match([1,2,3])>>>@match.when([2,2,2],let_=('one','two','thr'))...defcase1(one,two,thr):...return'case1'>>>@match.when([_,2,3],let_=('one','_','thr'))...defcase2(one,thr):...return'case2'>>>assertmatch.end=='case2'>>>match=Match('python')>>>@match.when(_.isdigit(),let_='moo')...defcase1(moo):...returnone>>>@match.when(_=='python',let_=('a'))...defcase2(a):...returna>>>assertmatch.end=='python'>>># with datatype>>>frommasala.datatypeimportRight,Left>>>match=Match(Either.right('python'))>>>@match.when(Right)...defcase_right(v):...returnv+' is right!'>>>@match.when(Left)...defcase_left(v):...assertFalse>>>assertmatch.end=='python is right!'

具有可选值的调用方法

>>>frommasalaimportPerhaps>>>p=Perhaps('hoge huga foo')>>>p.try_('replace','huga','muoo').try_('upper').get()'HOGE MUOO FOO'>>>p.apply(len).get()13>>>nonecase=Perhaps(None).try_('replace','huga','muoo').try_('upper')>>>nonecase.get()>>>nonecase.get_or('nnnnn')'nnnnn'

支架

python的测试版本是

  • 2.7
  • 3.4

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

推荐PyPI第三方库


热门话题
java的目标是从我的项目中删除不起作用的文件   java对for循环的理解   java我完成了在作业要求的位置查找字符的部分,但是如何从我找到的字符串中删除字符呢?   基于帧时的java动画   java请求无效。缺少XGoogUploadCommand标头   java如何在viewsource模式下使用openStream?   grpc grpc_ARG_KEEPALIVE_PERMIT_而不调用java服务器?   java如何通过Junit测试Web服务调用   如何在java中获取鼠标中键?   使用junit在spring测试中加载属性文件   Java中用于类的类修饰符   java多色文本图像   sql无法调试Java中的“连接到数据库失败”异常   java如何指定hibernate连接映射?   java Android工具栏不显示   java仿射转换不同的图形对象   使用终端的java问题   Java在tomcat上查找127.0.0.1失败