
    Dh	              	           d dl Z d dlmZmZmZmZ d dlmZ ddlm	Z	 ddl
mZ ddlmZmZ  ed      Zd	ed
ee   dee   fdZd
ee   d	edeee      fdZdee   d
ee   deee   ee   f   fdZy)    N)AsyncIterableListTupleTypeVar)maybe_await   )iter)islice)AnyIterable	PredicateTniterablereturnc                 x   K   | dk  rt        d      t        ||       2 cg c3 d{   }|7 6 c}S c c}w w)a	  
    Return the first n items of iterable as a list.

    If there are too few items in iterable, all of them are returned.
    n needs to be at least 0. If it is 0, an empty list is returned.

    Example::

        first_two = await take(2, [1, 2, 3, 4, 5])

    r   z(take's first parameter can't be negativeN)
ValueErrorr
   )r   r   items      }/var/www/fastuser/data/www/generator.snapmosaic.io/flask_app/venv/lib/python3.12/site-packages/aioitertools/more_itertools.pytaker      s=      	1uCDD#)(A#6774D7777s$   :51/
1515:c                   K   t        |       }t        ||       d{   }|g k7  r | t        ||       d{   }|g k7  ryy7 *7 w)a#  
    Break iterable into chunks of length n.

    The last chunk will be shorter if the total number of items is not
    divisible by n.

    Example::

        async for chunk in chunked([1, 2, 3, 4, 5], n=2):
            ...  # first iteration: chunk == [1, 2]; last one: chunk == [5]
    N)r	   r   )r   r   itchunks       r   chunkedr   "   sM      
hBq"+E
2+1bk! 2+  "s%   AAAA
	AA
A	predicatec                     K   t        |      t        j                         j                          fd}fd} |        |       fS w)a  
    A variant of :func:`aioitertools.takewhile` that allows complete access to the
    remainder of the iterator.

         >>> it = iter('ABCdEfGhI')
         >>> all_upper, remainder = await before_and_after(str.isupper, it)
         >>> ''.join([char async for char in all_upper])
         'ABC'
         >>> ''.join([char async for char in remainder])
         'dEfGhI'

    Note that the first iterator must be fully consumed before the second
    iterator can generate valid results.
    c                    K   2 3 d {   } t         |              d {   r|  (j                  |         y 7 67 6 j                  t               y wN)r   
set_resultset_exceptionStopAsyncIteration)elemr   r   
transitions    r   true_iteratorz'before_and_after.<locals>.true_iteratorK   s^      	 	$ 4111
%%d+	1  	  !34s5   AAAAAAAAAAc                 t   K   	  d {    2 3 d {   } |  7 # t         $ r Y y w xY w7 6 y wr   )r    )elmr   r"   s    r   remainder_iteratorz,before_and_after.<locals>.remainder_iteratorU   sJ     	##$  	 	#I $! 			s@   8% #% 86468% 	181868)r	   asyncioget_event_loopcreate_future)r   r   r#   r&   r   r"   s   `   @@r   before_and_afterr*   5   sF     $ 
hB'')779J5 ?.000s   A	A)r'   typingr   r   r   r   aioitertools.helpersr   builtinsr	   	itertoolsr
   typesr   r   r   intr   r   r*        r   <module>r3      s     6 6 ,   ) CL8# 8Q 8DG 8""KN "s "}T!W7M "&)1|)1'21~)1
=]1--.)1r2   