§
    +P„jÁ  ã                  óâ   — d Z ddlmZ ddlZddlZddlmZmZmZm	Z	m
Z
 eZeZ e
d¦  «        Z e
d¦  «        ZeZ e
d¦  «        Z e
d¦  «        Z e
d	¦  «        Zdd„Zedœd d„Zd!d„Zd"d„ZdS )#zItertools utils.é    )ÚannotationsN)ÚAnyÚCallableÚIterableÚIteratorÚTypeVarÚ_TÚ_KeyTÚ_KÚ_TinÚ_ToutÚxÚreturnc                ó   — | S )zPass through function.© )r   s    úX/root/disk_3tb/conda_envs/Huy-visual/lib/python3.11/site-packages/etils/epy/itertools.pyÚ	_identityr   (   s   € à	
€(ó    )ÚvalueÚiterableúIterable[_Tin]ÚkeyúCallable[[_Tin], _K]r   úCallable[[_Tin], _Tout]údict[_K, list[_Tout]]c               ó¶   — t          j        t          ¦  «        }| D ]/}| ||¦  «                                       ||¦  «        ¦  «         Œ0t	          |¦  «        S )a±  Similar to `itertools.groupby` but return result as a `dict()`.

  Example:

  ```python
  out = epy.groupby(
      ['555', '4', '11', '11', '333'],
      key=len,
      value=int,
  )
  # Order is consistent with above
  assert out == {
      3: [555, 333],
      1: [4],
      2: [11, 11],
  }
  ```

  Other difference with `itertools.groupby`:

   * Iterable do not need to be sorted. Order of the original iterator is
     preserved in the group.
   * Transformation can be applied to the value too

  Args:
    iterable: The iterable to group
    key: Mapping applied to group the values (should return a hashable)
    value: Mapping applied to the values

  Returns:
    The dict
  )ÚcollectionsÚdefaultdictÚlistÚappendÚdict)r   r   r   ÚgroupsÚvs        r   Úgroupbyr$   -   s[   € õL Ô"¥4Ñ(Ô(€&Øð $ð $€aØ
ˆ3ˆ3ˆq‰6Œ6„N×Ò˜%˜% ™(œ(Ñ#Ô#Ð#Ð#Ý	ˆf‰ŒÐr   úIterable[_T]Ú	predicateúCallable[[_T], bool]útuple[list[_T], list[_T]]c                óˆ   — g }g }| D ]8} ||¦  «        r|                      |¦  «         Œ#|                      |¦  «         Œ9||fS )a]  Split the iterable into 2 lists (false, true), based on the predicate.

  Example:

  ```python
  small, big = epy.splitby([100, 4, 4, 1, 200], lambda x: x > 10)
  assert small == [4, 4, 1]
  assert big == [100, 200]
  ```

  Args:
    iterable: The iterable to split
    predicate: Function applied to split

  Returns:
    False list, True list
  )r    )r   r&   Ú
false_listÚ	true_listr#   s        r   Úsplitbyr,   Y   sf   € ð( €*Ø€)Øð ð €aØ€y��|„|ð Ø×Ò�qÑÔÐÐà×Ò˜ÑÔÐÐØ	�YÐ	Ðr   ÚdictsúUnpack[dict[_KeyT, _ValuesT]]ú(Iterator[_KeyT, tuple[Unpack[_ValuesT]]]c               '  ó  ‡K  — t          t          j        | Ž ¦  «        }| d         }t          |¦  «        t          |¦  «        k    r"t	          d|t          |¦  «        z  › �¦  «        ‚|D ]!Š‰t          ˆfd„| D ¦   «         ¦  «        fV — Œ"dS )aÎ  Iterate over items of dictionaries grouped by their keys.

  Example:

  ```python
  d0 = {'a': 1, 'b': 2}
  d1 = {'a': 10, 'b': 20}
  d2 = {'a': 100, 'b': 200}

  list(epy.zip_dict(d0, d1, d2)) == [
      ('a', (1, 10, 100)),
      ('b', (2, 20, 200)),
  ]
  ```

  Args:
    *dicts: The dict to iterate over. Should all have the same keys

  Yields:
    The iterator of `(key, zip(*values))`

  Raises:
    KeyError: If dicts does not contain the same keys.
  r   zMissing keys: c              3  ó(   •K  — | ]}|‰         V — Œd S )Nr   )Ú.0Údr   s     €r   ú	<genexpr>zzip_dict.<locals>.<genexpr>›   s'   øè è € Ð+Ð+ �Q�s”VÐ+Ð+Ð+Ð+Ð+Ð+r   N)ÚsetÚ	itertoolsÚchainÚlenÚKeyErrorÚtuple)r-   Úall_keysÚd0r   s      @r   Úzip_dictr=   w   s©   øè è € õ8 •” %Ð(Ñ)Ô)€(ØˆQ„x€"åˆ�]„]•c˜"‘g”gÒÐÝ
Ð8 H­s°2©w¬wÑ$6Ð8Ð8Ñ
9Ô
9Ð9àð ,ð ,€cà
�uÐ+Ð+Ð+Ð+ UÐ+Ñ+Ô+Ñ+Ô+Ð
+Ð+Ð+Ð+Ð+ð,ð ,r   )r   r   r   r   )r   r   r   r   r   r   r   r   )r   r%   r&   r'   r   r(   )r-   r.   r   r/   )Ú__doc__Ú
__future__r   r   r6   Útypingr   r   r   r   r   ÚUnpackÚTypeVarTupler	   r
   Ú_ValuesTr   r   r   r   r$   r,   r=   r   r   r   ú<module>rD      s!  ðð Ð à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø Ð Ð Ð à =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =ð
 
€Ø€à€WˆT�]„]€àˆ�ÑÔ€Ø€à€WˆT�]„]€Ø€wˆv�„€Øˆ�ÑÔ€ðð ð ð ð &/ð	)ð )ð )ð )ð )ð )ðXð ð ð ð<$,ð $,ð $,ð $,ð $,ð $,r   