Metadata-Version: 1.0
Name: chainreaction
Version: 0.1.0
Summary: Wrapper module which provides iterable object with infix style method chaining.
Home-page: https://github.com/ghostreet/chainreaction
Author: Keita Oouchi
Author-email: keita.oouchi@gmail.com
License: BSD License
Description: About this module
        -----------------
        Wrapper module which provides iterable object with infix style method chaining.  
        
        Unreadble::
        
            >>> filter(lambda y: y % 2, map(lambda x: x + 1, iterable))
        
        Readable::
        
            >>> iterable = react(iterable)
            >>> iterable.map(lambda x: x + 1).filter(lambda y: y % 2)
        
        How to install
        --------------
        Requires python2.7 or later (include python3.x).
        You need *pip* or *setuptools* or *distribute*::
        
            $ pip install chainreaction
            $ easy_install chainreaction
        
        How to use
        ----------
        The simplest and an only way to use this module is to call the **react** function.  
        **react** is a factory function which looks up *'__iter__'* / *'__getitem__'* 
        from an given iterable, and returns wrapped object.
        
        Example to use::
        
            >>> from chainreaction.reactor import react
            >>> react("hello")
            >>> react([1, 2, 3])
            >>> react(iter([1, 2, 3])
            >>> class DictLike(dict):pass
            >>> react(DictLike())
        
        Chainable object support any methods of its wrapped object,
        and try to wrap their return value.  
        By convention, side effective methods return nothing, but chainable object
        returns its side affected object wrapped with appropriate wrappper.  
        If iterator was passed into **react**, it would be consumed when it called
        any iterative methods.
        
        Example to use::
        
            >>> tobewrapped = "hello"
            >>> wrapped = react(tobewrapped)
            >>> wrapped = wrapped.upper().map(lambda c: ord(c))
            >>> [chr(c) for c in wrapped.unwrap] = [c for c in tobewrapped.upper()]
            True
            >>> tobewrapped = [1, 2, 3]
            >>> wrapped = react(tobewrapped)
            >>> wrapped.append(4).count()
            4
            >>> len(tobewrapped)
            4
        
        If an iterator was given, this iterator would be consumed
        when it called any method::
        
            >>> tobewrapped = iter([1,2,3])
            >>> wrapped = react(tobewrapped)
            >>> wrapped.count()
            4
            >>> len(list(tobewrapped))
            0
            
        Tiny percent encoding implementation example::
        
            >>> test = bytes("hello world-._~", encoding="UTF-8")
            >>> wrapped = react(test)
            >>> safe = set()
            >>> react("0123456789").foreach(lambda c: safe.add(ord(c)))
            >>> react(range(ord('a'), ord('z') + 1)).foreach(lambda b: safe.add(b))
            >>> react(range(ord('A'), ord('Z') + 1)).foreach(lambda b: safe.add(b))
            >>> react("-._~").foreach(lambda c: safe.add(ord(c)))
            >>> test = wrapped.map(lambda b: b if b > 0 else 256 + b)
            >>> test = test.map(lambda i: '+' if chr(i).isspace() else chr(i) if i in safe else "%{0:x}".format(i))
            >>> test.mkstring.unwrap == "hello+world-._~"
            True
        
        Basic API
        ---------
        #. unwrap
            Decorated with *@property*.
        #. dump
            Elements dump.
        #. isiterator
            True if wrapped object is iterator.
        #. foreach(f)
            Applies a given f to all elements.
        #. filter(pred)
            Selects all elements satisfying a given predicate.
        #. map(f)
            Builds a new collection by applying a given f.
        #. forall(pred)
            True if all elements a given satisfy predicate.
        #. forany(pred)
            True if any elements a given satisfy predicate.
        #. dropwhile(pred)
            Drops longest prefix of elements that satisfy a given predicate.
        #. dropright(pred)
            Drops longest suffix of elements that satisfy a given predicate.
        #. takwhile(pred)
            Takes longest prefix of elements that satisfy a given predicate.
        #. takeright(pred)
            Takes longest suffix of elements that satisfy a given predicate.
        #. mkstring(joiner="")
            Returns wrapped str object using a joiner string.
        #. counts(pred)
            Counts the number of elements that satisfy a given predicate.
        #. contains(key)
            Tests whether this wrapped object contains a given key as an element.
        #. reduce(f)
            Returns a value(not wrapped) using a given f.
            
        iterator specific API
        ^^^^^^^^^^^^^^^^^^^^^
        #. tolist
            Returns a new list wrapped.
        #. totuple
            Returns a new tuple wrapped.
        #. toset
            Returns a new set wrapped.
            
        str, bytes, bytearray specific API
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        #. reverse
            Returns a new reversed str wrapped.
        
        seq specific API
        ^^^^^^^^^^^^^^^^
        #. accumulate(f)
            Returns a seq of accumulated value.
        #. reverse
            Returns a new reversed seq wrapped.
        #. sort
            Returns a new sorted seq wrapped.
        #. toset
            Returns a new set wrapped.
        
        set specific API
        ^^^^^^^^^^^^^^^^
        #. min
            Returns a minimum value.
        #. max
            Returns a maximum value.
        
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.0
Classifier: Programming Language :: Python :: 3.1
Classifier: Programming Language :: Python :: 3.2
Classifier: Topic :: Software Development :: Libraries :: Python Modules
