o
    tBh#                     @   sl   d Z ddlZddlmZ dZG dd deZG dd	 d	eZG d
d deZ	efddZ
dd Zdd ZdS )z5
Method chaining interface.

.. versionadded:: 1.0.0
    N   )UNSET)chaintapthruc                   @   s\   e Zd ZdZeZefddZdd Zdd Z	dd	 Z
d
d Zedd Zdd Zdd ZdS )Chainz-Enables chaining of :attr:`module` functions.c                 C   s
   || _ d S )N_valueselfvalue r   f/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/pydash/chaining.py__init__   s   
zChain.__init__c                 C   s
   | | j S )z
        Return current value of the chain operations.

        Returns:
            mixed: Current value of chain operations.
        r   r   r   r   r   r      s   
zChain.valuec                 C   s   | j |  S )z
        Return current value as string.

        Returns:
            str: Current value of chain operations casted to ``str``.
        )module	to_stringr   r   r   r   r   r   %   s   zChain.to_stringc                 C   s   t |  S )z
        Executes the chained sequence and returns the wrapped result.

        Returns:
            Chain: New instance of :class:`Chain` with resolved value from
                previous :class:`Class`.
        )r   r   r   r   r   r   commit.   s   zChain.commitc                 C   sv   | j }g }t|dr"|g}t|j tr"|j }|d| t|j tst|}|D ]}t|j |j|ji |j}q(|S )z
        Return a clone of the chained sequence planting `value` as the wrapped value.

        Args:
            value (mixed): Value to plant as the initial chain value.
        r	   r   )	r	   hasattr
isinstanceChainWrapperinsertr   methodargskwargs)r   r   wrapperwrappersclonewrapr   r   r   plant8   s   
zChain.plantc                 C   s\   |dv r| S t | j|d}t|s|dst | j|d d}t|s,| jd| |S )a  
        Return valid :attr:`module` method.

        Args:
            name (str): Name of pydash method to get.

        Returns:
            function: :attr:`module` callable.

        Raises:
            InvalidMethod: Raised if `name` is not a valid :attr:`module` method.
        )__wrapped__N_zInvalid pydash method: )getattrr   callableendswithInvalidMethod)clsnamer   r   r   r   
get_methodQ   s   zChain.get_methodc                 C   s   t | j| |S )aJ  
        Proxy attribute access to :attr:`module`.

        Args:
            attr (str): Name of :attr:`module` function to chain.

        Returns:
            ChainWrapper: New instance of :class:`ChainWrapper` with value passed on.

        Raises:
            InvalidMethod: Raised if `attr` is not a valid function.
        )r   r	   r(   r   attrr   r   r   __getattr__r   s   zChain.__getattr__c                 C   s   t | jtr| j|}|S )z
        Return result of passing `value` through chained methods.

        Args:
            value (mixed): Initial value to pass through chained methods.

        Returns:
            mixed: Result of method chain evaluation of `value`.
        )r   r	   r   unwrapr
   r   r   r   __call__   s   
zChain.__call__N)__name__
__module____qualname____doc__pydr   r   r   r   r   r   r   classmethodr(   r+   r-   r   r   r   r   r      s    		

 r   c                   @   s4   e Zd ZdZdd Zdd ZefddZdd	 Zd
S )r   zGWrap :class:`Chain` method call within a :class:`ChainWrapper` context.c                 C   s   || _ || _d| _i | _d S )Nr   )r	   r   r   r   )r   r   r   r   r   r   r      s   
zChainWrapper.__init__c                 C   s   | j | j }| j |_|S )z!Generate a copy of this instance.)	__class____new____dict__copy)r   newr   r   r   	_generate   s   zChainWrapper._generatec                 C   sh   |   }t|jtr|j||_nt|ts|tur||_|jtur&|j}|j|g|jR i |jS )z
        Execute :meth:`method` with :attr:`_value`, :attr:`args`, and :attr:`kwargs`.

        If :attr:`_value` is an instance of :class:`ChainWrapper`, then unwrap it before calling
        :attr:`method`.
        )	r9   r   r	   r   r,   r   r   r   r   )r   r   r   r   r   r   r,      s   
zChainWrapper.unwrapc                 O   s   || _ || _t| S )a%  
        Invoke the :attr:`method` with :attr:`value` as the first argument and return a new
        :class:`Chain` object with the return value.

        Returns:
            Chain: New instance of :class:`Chain` with the results of :attr:`method` passed in as
                value.
        )r   r   r   )r   r   r   r   r   r   r-      s   	zChainWrapper.__call__N)	r.   r/   r0   r1   r   r9   r   r,   r-   r   r   r   r   r      s    r   c                   @   s$   e Zd ZdZdd ZefddZdS )_Dashz}Class that provides attribute access to valid :mod:`pydash` methods and callable access to
    :mod:`pydash` method chaining.c                 C   s
   t |S )z"Proxy to :meth:`Chain.get_method`.)r   r(   r)   r   r   r   r+      s   
z_Dash.__getattr__c                 C   s   t |S )zAReturn a new instance of :class:`Chain` with `value` as the seed.r   r
   r   r   r   r-      s   z_Dash.__call__N)r.   r/   r0   r1   r+   r   r-   r   r   r   r   r:      s    r:   c                 C   s   t | S )az  
    Creates a :class:`Chain` object which wraps the given value to enable intuitive method chaining.
    Chaining is lazy and won't compute a final value until :meth:`Chain.value` is called.

    Args:
        value (mixed): Value to initialize chain operations with.

    Returns:
        :class:`Chain`: Instance of :class:`Chain` initialized with `value`.

    Example:

        >>> chain([1, 2, 3, 4]).map(lambda x: x * 2).sum().value()
        20
        >>> chain().map(lambda x: x * 2).sum()([1, 2, 3, 4])
        20

        >>> summer = chain([1, 2, 3, 4]).sum()
        >>> new_summer = summer.plant([1, 2])
        >>> new_summer.value()
        3
        >>> summer.value()
        10

        >>> def echo(item): print(item)
        >>> summer = chain([1, 2, 3, 4]).for_each(echo).sum()
        >>> committed = summer.commit()
        1
        2
        3
        4
        >>> committed.value()
        10
        >>> summer.value()
        1
        2
        3
        4
        10

    .. versionadded:: 1.0.0

    .. versionchanged:: 2.0.0
        Made chaining lazy.

    .. versionchanged:: 3.0.0

        - Added support for late passing of `value`.
        - Added :meth:`Chain.plant` for replacing initial chain value.
        - Added :meth:`Chain.commit` for returning a new :class:`Chain` instance initialized with
          the results from calling :meth:`Chain.value`.
    r;   )r   r   r   r   r      s   5r   c                 C   s   ||  | S )a  
    Invokes `interceptor` with the `value` as the first argument and then returns `value`. The
    purpose of this method is to "tap into" a method chain in order to perform operations on
    intermediate results within the chain.

    Args:
        value (mixed): Current value of chain operation.
        interceptor (callable): Function called on `value`.

    Returns:
        mixed: `value` after `interceptor` call.

    Example:

        >>> data = []
        >>> def log(value): data.append(value)
        >>> chain([1, 2, 3, 4]).map(lambda x: x * 2).tap(log).value()
        [2, 4, 6, 8]
        >>> data
        [[2, 4, 6, 8]]

    .. versionadded:: 1.0.0
    r   r   interceptorr   r   r   r     s   r   c                 C   s   || S )a  
    Returns the result of calling `interceptor` on `value`. The purpose of this method is to pass
    `value` through a function during a method chain.

    Args:
        value (mixed): Current value of chain operation.
        interceptor (callable): Function called with `value`.

    Returns:
        mixed: Results of ``interceptor(value)``.

    Example:

        >>> chain([1, 2, 3, 4]).thru(lambda x: x * 2).value()
        [1, 2, 3, 4, 1, 2, 3, 4]

    .. versionadded:: 2.0.0
    r   r<   r   r   r   r   *  s   r   )r1   pydashr2   helpersr   __all__objectr   r   r:   r   r   r   r   r   r   r   <module>   s    ~88