B ÍAÒ[›$ã@sÖdZddlmZmZmZddlmZmZddlZddlm Z ddl m Z dd„Z e r¨ddl Z d d „Zd d „Zd d„Zdd„ZeZeZeZddlmZeZdddddgZn*ddlZejZejZejZejZejZgZdS)a, This module is designed to be used as follows:: from past.builtins.noniterators import filter, map, range, reduce, zip And then, for example:: assert isinstance(range(5), list) The list-producing functions this brings in are:: - ``filter`` - ``map`` - ``range`` - ``reduce`` - ``zip`` é)ÚdivisionÚabsolute_importÚprint_function)ÚchainÚstarmapN)Ú basestring)ÚPY3cCst t||ƒ¡S)N)rÚ from_iterableÚmap)ÚfÚitems©r úK/opt/alt/python37/lib/python3.7/site-packages/past/builtins/noniterators.pyÚflatmapsrcGs^t|dƒ}t|dtƒr,|ƒ tj|Ž¡St|dttfƒrL|tj|ŽƒSttj|ŽƒSdS)a* filter(function or None, sequence) -> list, tuple, or string Return those items of sequence for which function(item) is true. If function is None, return the items that are true. If sequence is a tuple or string, return the same type, else return a list. éN)ÚtypeÚ isinstancerÚjoinÚbuiltinsÚfilterÚtupleÚlist)ÚargsZmytyper r rÚ oldfilter$s  rc GsŽtj|Ž}t|ƒ}t|ƒdkr"gS|dkr0|}ntt||ƒƒ}y(tdd„|Dƒƒdkrdtt |¡ƒSWn"tk rˆ}zWdd}~XYnX|S)a map(function, sequence[, sequence, ...]) -> list Return a list of the results of applying the function to the items of the argument sequence(s). If more than one sequence is given, the function is called with an argument list consisting of the corresponding item of each sequence, substituting None for missing values when not all sequences have the same length. If the function is None, return a list of the items of the sequence (or a list of tuples if more than one sequence). Test cases: >>> oldmap(None, 'hello world') ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] >>> oldmap(None, range(4)) [0, 1, 2, 3] More test cases are in past.tests.test_builtins. rNcSsg|] }t|ƒ‘qSr )Úlen)Ú.0Úitemr r rú Xszoldmap..r) Ú itertoolsÚ zip_longestrrrÚmaxrr Ú TypeError)ÚfuncÚ iterablesZzippedÚlÚresultÚer r rÚoldmap8s  r'cOsttj||ŽƒS)N)rrÚrange)rÚkwargsr r rÚoldrangeûsr*cOsttj||ŽƒS)N)rrÚzip)rr)r r rÚoldzipþsr,)Úreducerr r(r-r+)Ú__doc__Ú __future__rrrrrrZ past.typesrZ past.utilsrrrrr'r*r,rr r(Ú functoolsr-r+Ú__all__Z __builtin__r r r rÚs4  D