
    E#i"                         S SK r S SKrS SKJr  S SKJr  SrS rS rS r	\
4S jr\
4S	 jr\
4S
 jr\
4S jr\
4S jr\
4S jr\
4S jrS r\
4S jrS\
4S jrSS jrg)    N)reduce)Mapping)merge
merge_withvalmapkeymapitemmap	valfilter	keyfilter
itemfilterassocdissocassoc_in	update_inget_inc                     UR                  S[        5      nU(       a6  [        SR                  U R                  UR                  5       S   5      5      eU$ )Nfactoryz,{}() got an unexpected keyword argument '{}'r   )popdict	TypeErrorformat__name__popitem)fkwargsr   s      b/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/toolz/dicttoolz.py_get_factoryr      sJ    jjD)G %vajj&..2B12EFH 	HN    c                      [        U 5      S:X  a  [        U S   [        5      (       d  U S   n [        [        U5      nU" 5       nU  H  nUR                  U5        M     U$ )zMerge a collection of dictionaries

>>> merge({1: 'one'}, {2: 'two'})
{1: 'one', 2: 'two'}

Later dictionaries have precedence

>>> merge({1: 2, 3: 4}, {3: 3, 4: 4})
{1: 2, 3: 3, 4: 4}

See Also:
    merge_with
   r   )len
isinstancer   r   r   update)dictsr   r   rvds        r   r   r      sU     5zQz%(G<<a5&)G	B
		! Ir   c                 l   [        U5      S:X  a  [        US   [        5      (       d  US   n[        [        U5      n[
        R                  " S 5      nU H&  nUR                  5        H  u  pgXF   " U5        M     M(     U" 5       nUR                  5        H  u  pgU " UR                  5      X'   M     U$ )a  Merge dictionaries and apply function to combined values

A key may occur in more than one dict, and all values mapped from the key
will be passed to the function as a list, such as func([val1, val2, ...]).

>>> merge_with(sum, {1: 1, 2: 2}, {1: 10, 2: 20})
{1: 11, 2: 22}

>>> merge_with(first, {1: 1, 2: 2}, {2: 20, 3: 30})  # doctest: +SKIP
{1: 1, 2: 2, 3: 30}

See Also:
    merge
r    r   c                      / R                   $ N)append r   r   <lambda>merge_with.<locals>.<lambda>>   s    RYYr   )	r!   r"   r   r   r   collectionsdefaultdictitems__self__)	funcr$   r   r   valuesr&   kvresults	            r   r   r   +   s     5zQz%(G<<a:v.G$$%67FGGIDAIaL   YF$	 Mr   c           
          U" 5       nUR                  [        UR                  5       [        XR	                  5       5      5      5        U$ )zApply function to values of dictionary

>>> bills = {"Alice": [20, 15, 30], "Bob": [10, 35]}
>>> valmap(sum, bills)  # doctest: +SKIP
{'Alice': 65, 'Bob': 45}

See Also:
    keymap
    itemmap
)r#   zipkeysmapr3   r2   r&   r   r%   s       r   r   r   I   s4     
BIIc!&&(Chhj123Ir   c           	          U" 5       nUR                  [        [        XR                  5       5      UR	                  5       5      5        U$ )zApply function to keys of dictionary

>>> bills = {"Alice": [20, 15, 30], "Bob": [10, 35]}
>>> keymap(str.lower, bills)  # doctest: +SKIP
{'alice': [20, 15, 30], 'bob': [10, 35]}

See Also:
    valmap
    itemmap
)r#   r8   r:   r9   r3   r;   s       r   r   r   Y   s4     
BIIc#dFFH%qxxz23Ir   c                 d    U" 5       nUR                  [        XR                  5       5      5        U$ )zApply function to items of dictionary

>>> accountids = {"Alice": 10, "Bob": 20}
>>> itemmap(reversed, accountids)  # doctest: +SKIP
{10: "Alice", 20: "Bob"}

See Also:
    keymap
    valmap
)r#   r:   r0   r;   s       r   r	   r	   i   s'     
BIIc$	"#Ir   c                 l    U" 5       nUR                  5        H  u  pEU " U5      (       d  M  XSU'   M     U$ )zFilter items in dictionary by value

>>> iseven = lambda x: x % 2 == 0
>>> d = {1: 2, 2: 3, 3: 4, 4: 5}
>>> valfilter(iseven, d)
{1: 2, 3: 4}

See Also:
    keyfilter
    itemfilter
    valmap
r0   	predicater&   r   r%   r4   r5   s         r   r
   r
   y   4     
B	Q<<qE  Ir   c                 l    U" 5       nUR                  5        H  u  pEU " U5      (       d  M  XSU'   M     U$ )zFilter items in dictionary by key

>>> iseven = lambda x: x % 2 == 0
>>> d = {1: 2, 2: 3, 3: 4, 4: 5}
>>> keyfilter(iseven, d)
{2: 3, 4: 5}

See Also:
    valfilter
    itemfilter
    keymap
r?   r@   s         r   r   r      rB   r   c                 p    U" 5       nUR                  5        H  nU " U5      (       d  M  Uu  pVXcU'   M     U$ )zFilter items in dictionary by item

>>> def isvalid(item):
...     k, v = item
...     return k % 2 == 0 and v < 4

>>> d = {1: 2, 2: 3, 3: 4, 4: 5}
>>> itemfilter(isvalid, d)
{2: 3}

See Also:
    keyfilter
    valfilter
    itemmap
r?   )rA   r&   r   r%   itemr4   r5   s          r   r   r      s9      
B	T??DAqE  Ir   c                 >    U" 5       nUR                  U 5        X$U'   U$ )zReturn a new dict with new key value pair

New dict has d[key] set to value. Does not modify the initial dictionary.

>>> assoc({'x': 1}, 'x', 2)
{'x': 2}
>>> assoc({'x': 1}, 'y', 3)   # doctest: +SKIP
{'x': 1, 'y': 3}
)r#   )r&   keyvaluer   d2s        r   r   r      s"     
BIIaLsGIr   c                 
   [        [        U5      nU" 5       n[        U5      [        U 5      S-  :  a%  UR                  U 5        U H  nXT;   d  M
  XE	 M     U$ [	        U 5      nUR                  U5        U H	  nX   XG'   M     U$ )a  Return a new dict with the given key(s) removed.

New dict has d[key] deleted for each supplied key.
Does not modify the initial dictionary.

>>> dissoc({'x': 1, 'y': 2}, 'y')
{'x': 1}
>>> dissoc({'x': 1, 'y': 2}, 'y', 'x')
{}
>>> dissoc({'x': 1}, 'y') # Ignores missing keys
{'x': 1}
g333333?)r   r   r!   r#   setdifference_update)r&   r9   r   r   rI   rG   	remainingr4   s           r   r   r      s     66*G	B
4y3q6B;
		!CyG  I	 F	##D)ADBE Ir   c                 (   ^ [        XU4S jTU5      $ )a  Return a new dict with new, potentially nested, key value pair

>>> purchase = {'name': 'Alice',
...             'order': {'items': ['Apple', 'Orange'],
...                       'costs': [0.50, 1.25]},
...             'credit card': '5555-1234-1234-1234'}
>>> assoc_in(purchase, ['order', 'costs'], [0.25, 1.00]) # doctest: +SKIP
{'credit card': '5555-1234-1234-1234',
 'name': 'Alice',
 'order': {'costs': [0.25, 1.00], 'items': ['Apple', 'Orange']}}
c                    > T$ r)   r+   )xrH   s    r   r,   assoc_in.<locals>.<lambda>   s    r   )r   )r&   r9   rH   r   s     ` r   r   r      s     Qoug>>r   c                    [        U5      n[        U5      nU" 5       =pxUR                  U 5        U H5  n	X`;   a  X   n U" 5       n
U
R                  U 5        OU" 5       =p
U
=X'   nU	nM7     X`;   a  U" X   5      X'   U$ U" U5      X'   U$ )a  Update value in a (potentially) nested dictionary

inputs:
d - dictionary on which to operate
keys - list or tuple giving the location of the value to be changed in d
func - function to operate on that value

If keys == [k0,..,kX] and d[k0]..[kX] == v, update_in returns a copy of the
original dictionary with v replaced by func(v), but does not mutate the
original dictionary.

If k0 is not a key in d, update_in creates nested dictionaries to the depth
specified by the keys, with the innermost value set to func(default).

>>> inc = lambda x: x + 1
>>> update_in({'a': 0}, ['a'], inc)
{'a': 1}

>>> transaction = {'name': 'Alice',
...                'purchase': {'items': ['Apple', 'Orange'],
...                             'costs': [0.50, 1.25]},
...                'credit card': '5555-1234-1234-1234'}
>>> update_in(transaction, ['purchase', 'costs'], sum) # doctest: +SKIP
{'credit card': '5555-1234-1234-1234',
 'name': 'Alice',
 'purchase': {'costs': 1.75, 'items': ['Apple', 'Orange']}}

>>> # updating a value when k0 is not in d
>>> update_in({}, [1, 2, 3], str, default="bar")
{1: {2: {3: 'bar'}}}
>>> update_in({1: 'foo'}, [2, 3, 4], inc, 0)
{1: 'foo', 2: {3: {4: 1}}}
)iternextr#   )r&   r9   r2   defaultr   ksr4   r%   innerrG   dtemps              r   r   r      s    D 
dBRABIIaL6AIELLO	!A  5  	v: I =Ir   c                      [        [        R                  X5      $ ! [        [        [
        4 a    U(       a  e Us $ f = f)a  Returns coll[i0][i1]...[iX] where [i0, i1, ..., iX]==keys.

If coll[i0][i1]...[iX] cannot be found, returns ``default``, unless
``no_default`` is specified, then it raises KeyError or IndexError.

``get_in`` is a generalization of ``operator.getitem`` for nested data
structures such as dictionaries and lists.

>>> transaction = {'name': 'Alice',
...                'purchase': {'items': ['Apple', 'Orange'],
...                             'costs': [0.50, 1.25]},
...                'credit card': '5555-1234-1234-1234'}
>>> get_in(['purchase', 'items', 0], transaction)
'Apple'
>>> get_in(['name'], transaction)
'Alice'
>>> get_in(['purchase', 'total'], transaction)
>>> get_in(['purchase', 'items', 'apple'], transaction)
>>> get_in(['purchase', 'items', 10], transaction)
>>> get_in(['purchase', 'total'], transaction, 0)
0
>>> get_in(['y'], {}, no_default=True)
Traceback (most recent call last):
    ...
KeyError: 'y'

See Also:
    itertoolz.get
    operator.getitem
)r   operatorgetitemKeyError
IndexErrorr   )r9   collrU   
no_defaults       r   r   r   /  s;    >h&&33j), s    >>)NF)rZ   r.   	functoolsr   collections.abcr   __all__r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r+   r   r   <module>rc      s       #A
0< !   !   "   %) ( %) ( &* 0 "&  : &* ? &*4 7t$r   