
    &`i                     >    d dl mZ d dlmZmZ  G d de          ZdS )    )defaultdict)AnyCallablec                   @     e Zd ZdZdeegef         f fdZd Z xZ	S )LambdaDefaultDictac  A defaultdict that creates default values based on the associated key.

    Note that the standard defaultdict can only produce default values (via its factory)
    that are independent of the key under which they are stored.
    As opposed to that, the lambda functions used as factories for this
    `LambdaDefaultDict` class do accept a single argument: The missing key.
    If a missing key is accessed by the user, the provided lambda function is called
    with this missing key as its argument. The returned value is stored in the
    dictionary under that key and returned.

    Example:

        In this example, if you try to access a key that doesn't exist, it will call
        the lambda function, passing it the missing key. The function will return a
        string, which will be stored in the dictionary under that key.

        .. testcode::

            from ray.rllib.utils.lambda_defaultdict import LambdaDefaultDict

            default_dict = LambdaDefaultDict(lambda missing_key: f"Value for {missing_key}")
            print(default_dict["a"])

        .. testoutput::

            Value for a
    default_factoryc                     t          |          st          d           t                      j        dg|R i | || _        dS )zInitializes a LambdaDefaultDict instance.

        Args:
            default_factory: The default factory callable, taking a string (key)
                and returning the default value to use for that key.
        z"First argument must be a Callable!N)callable	TypeErrorsuper__init__r   )selfr   argskwargs	__class__s       v/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/rllib/utils/lambda_defaultdict.pyr   zLambdaDefaultDict.__init__"   s\     (( 	B@AAA 	///////.    c                 :    |                      |          x| |<   }|S )N)r   )r   keyvalues      r   __missing__zLambdaDefaultDict.__missing__1   s#     00555S	Er   )
__name__
__module____qualname____doc__r   strr   r   r   __classcell__)r   s   @r   r   r      sh         8/#(< / / / / / /      r   r   N)collectionsr   typingr   r   r    r   r   <module>r!      sc    # # # # # #                / / / / / / / / / /r   