# Path: generators/chunk_on.py
# def chunk_on(pipeline, new_chunk_signal, output_type=tuple):
#     ''' split the stream into seperate chunks based on a new chunk signal '''
#     assert iterable(pipeline), 'chunks needs pipeline to be iterable'
#     assert callable(new_chunk_signal), 'chunks needs new_chunk_signal to be callable'
#     assert callable(output_type), 'chunks needs output_type to be callable'
#     
#     holder = []
#     
#     for signal, group in groupby(pipeline, new_chunk_signal):
#         if signal:
#             for i in group:
#                 holder = [i]
#                 break
#             for i in group:
#                 yield output_type(holder)
#                 holder = [i]
#         else:
#             yield output_type(
#                 chain(
#                     holder, 
#                     group
#                 )
#             )
#             holder = []
#     if holder:
#         yield output_type(holder)
# 
# Path: generators/apply_to_last.py
# @strict_globals(iterable=iterable)
# def apply_to_last(stream, fn):
#     ''' applies a given function to the last item in a generator/stream '''
#     assert iterable(stream), 'apply_to_last needs stream to be iterable'
#     assert callable(fn), 'apply_to_last needs fn to be callable'
# 
#     stream = iter(stream)
#     for previous in stream:
#         for current in stream:
#             yield previous
#             previous = current
#         yield fn(previous)
#         break
# 
# Path: generators/iterable.py
# @noglobals
# def iterable(target):
#     ''' returns true if the given argument is iterable '''
#     if any(i in ('next', '__next__', '__iter__') for i in dir(target)):
#         return True
#     else:
#         try:
#             iter(target)
#             return True
#         except:
#             return False


    from itertools import zip_longest
    from itertools import izip_longest as zip_longest, imap as map
from strict_functions import strict_globals
from .chunk_on import chunk_on
from .apply_to_last import apply_to_last
from .iterable import iterable
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Cody Kochmann

try:
except ImportError:
else:
    map = map



@strict_globals(zip_longest=zip_longest, apply_to_last=apply_to_last, chunk_on=chunk_on, iterable=iterable, map=map)
def _chunks(stream, chunk_size, output_type=tuple):
    ''' yields a stream chunked at a specific size '''
    assert iterable(stream), 'chunks needs stream to be iterable'
    assert (isinstance(chunk_size, int) and chunk_size > 0) or callable(chunk_size), 'chunks needs chunk_size to be a positive int or callable'
    assert callable(output_type), 'chunks needs output_type to be callable'
    if callable(chunk_size):
        ''' chunk_size is acting as a separator function '''

# Path: generators/chunk_on.py
# def chunk_on(pipeline, new_chunk_signal, output_type=tuple):
#     ''' split the stream into seperate chunks based on a new chunk signal '''
#     assert iterable(pipeline), 'chunks needs pipeline to be iterable'
#     assert callable(new_chunk_signal), 'chunks needs new_chunk_signal to be callable'
#     assert callable(output_type), 'chunks needs output_type to be callable'
#     
#     holder = []
#     
#     for signal, group in groupby(pipeline, new_chunk_signal):
#         if signal:
#             for i in group:
#                 holder = [i]
#                 break
#             for i in group:
#                 yield output_type(holder)
#                 holder = [i]
#         else:
#             yield output_type(
#                 chain(
#                     holder, 
#                     group
#                 )
#             )
#             holder = []
#     if holder:
#         yield output_type(holder)
# 
# Path: generators/apply_to_last.py
# @strict_globals(iterable=iterable)
# def apply_to_last(stream, fn):
#     ''' applies a given function to the last item in a generator/stream '''
#     assert iterable(stream), 'apply_to_last needs stream to be iterable'
#     assert callable(fn), 'apply_to_last needs fn to be callable'
# 
#     stream = iter(stream)
#     for previous in stream:
#         for current in stream:
#             yield previous
#             previous = current
#         yield fn(previous)
#         break
# 
# Path: generators/iterable.py
# @noglobals
# def iterable(target):
#     ''' returns true if the given argument is iterable '''
#     if any(i in ('next', '__next__', '__iter__') for i in dir(target)):
#         return True
#     else:
#         try:
#             iter(target)
#             return True
#         except:
#             return False


# Path: generators/chunks.py
    from itertools import zip_longest
    from itertools import izip_longest as zip_longest, imap as map
from strict_functions import strict_globals
from .chunk_on import chunk_on
from .apply_to_last import apply_to_last
from .iterable import iterable

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Cody Kochmann

try:
except ImportError:
else:
    map = map



@strict_globals(zip_longest=zip_longest, apply_to_last=apply_to_last, chunk_on=chunk_on, iterable=iterable, map=map)
def _chunks(stream, chunk_size, output_type=tuple):
    ''' yields a stream chunked at a specific size '''
    assert iterable(stream), 'chunks needs stream to be iterable'
    assert (isinstance(chunk_size, int) and chunk_size > 0) or callable(chunk_size), 'chunks needs chunk_size to be a positive int or callable'
    assert callable(output_type), 'chunks needs output_type to be callable'
    if callable(chunk_size):
        ''' chunk_size is acting as a separator function '''

        for chunk in chunk_on(stream, chunk_size, output_type=output_type):