# Path: paco/pipe.py
# def overload(fn):
#     """
#     Overload a given callable object to be used with ``|`` operator
#     overloading.
# 
#     This is especially used for composing a pipeline of
#     transformation over a single data set.
# 
#     Arguments:
#         fn (function): target function to decorate.
# 
#     Raises:
#         TypeError: if function or coroutine function is not provided.
# 
#     Returns:
#         function: decorated function
#     """
#     if not isfunction(fn):
#         raise TypeError('paco: fn must be a callable object')
# 
#     spec = getargspec(fn)
#     args = spec.args
#     if not spec.varargs and (len(args) < 2 or args[1] != 'iterable'):
#         raise ValueError('paco: invalid function signature or arity')
# 
#     @functools.wraps(fn)
#     def decorator(*args, **kw):
#         # Check function arity
#         if len(args) < 2:
#             return PipeOverloader(fn, args, kw)
#         # Otherwise, behave like a normal wrapper
#         return fn(*args, **kw)
# 
#     return decorator


import sys
import pytest
import asyncio
import paco
from paco.pipe import overload

        @asyncio.coroutine
        def __anext__(self):
            if self.pos == len(self.values):
                raise StopAsyncIteration  # noqa

            value = self.values[self.pos]
            self.pos += 1
            return value

    @asyncio.coroutine
    def task(numbers):
        return (yield from (AsyncGenerator(numbers)
                            | paco.map(mapper)
                            | paco.reduce(reducer, initializer=0)))

    result = paco.run(task([1, 2, 3, 4, 5]))
    assert result == 30


def test_overload_error():
    with pytest.raises(TypeError, message='fn must be a callable object'):
        overload(None)

    with pytest.raises(ValueError,
                       messsage='invalid function signature or arity'):
        overload(lambda x: True)

    with pytest.raises(ValueError,
                       messsage='invalid function signature or arity'):

# Path: paco/pipe.py
# def overload(fn):
#     """
#     Overload a given callable object to be used with ``|`` operator
#     overloading.
# 
#     This is especially used for composing a pipeline of
#     transformation over a single data set.
# 
#     Arguments:
#         fn (function): target function to decorate.
# 
#     Raises:
#         TypeError: if function or coroutine function is not provided.
# 
#     Returns:
#         function: decorated function
#     """
#     if not isfunction(fn):
#         raise TypeError('paco: fn must be a callable object')
# 
#     spec = getargspec(fn)
#     args = spec.args
#     if not spec.varargs and (len(args) < 2 or args[1] != 'iterable'):
#         raise ValueError('paco: invalid function signature or arity')
# 
#     @functools.wraps(fn)
#     def decorator(*args, **kw):
#         # Check function arity
#         if len(args) < 2:
#             return PipeOverloader(fn, args, kw)
#         # Otherwise, behave like a normal wrapper
#         return fn(*args, **kw)
# 
#     return decorator


# Path: tests/pipe_test.py
import sys
import pytest
import asyncio
import paco
from paco.pipe import overload


        @asyncio.coroutine
        def __anext__(self):
            if self.pos == len(self.values):
                raise StopAsyncIteration  # noqa

            value = self.values[self.pos]
            self.pos += 1
            return value

    @asyncio.coroutine
    def task(numbers):
        return (yield from (AsyncGenerator(numbers)
                            | paco.map(mapper)
                            | paco.reduce(reducer, initializer=0)))

    result = paco.run(task([1, 2, 3, 4, 5]))
    assert result == 30


def test_overload_error():
    with pytest.raises(TypeError, message='fn must be a callable object'):
        overload(None)

    with pytest.raises(ValueError,
                       messsage='invalid function signature or arity'):
        overload(lambda x: True)

    with pytest.raises(ValueError,
                       messsage='invalid function signature or arity'):

        overload(lambda x, y: True)