"""Basic python utility functions"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/api/utilities/basic.ipynb.

# %% auto 0
__all__ = ['get_item', 'filter_args', 'filter_out_args']

# %% ../../nbs/api/utilities/basic.ipynb
import inspect
from typing import *

# %% ../../nbs/api/utilities/basic.ipynb
def get_item(
    l:Sequence,           # Sequence to get item of
    i:int,                # Index of item to get
    default:Optional=None # Default value to return if sequence does not contain item at index
)->Any:                   # Item or default value
    """Return item at index `i` from sequence `l` or `default` if item does not exist."""
    try: return l[i]
    except IndexError: return default

# %% ../../nbs/api/utilities/basic.ipynb
def filter_args(
    fnc:Callable, # Function to test keyword arguments against
    **kwargs      # Keyword arguments to test
)->dict:          # Keyword arguments defined in signature of `fnc` 
    """Return only keyword arguments defined in signature of function `fnc`."""
    return {k: v for k, v in kwargs.items() if k in inspect.signature(fnc).parameters}

# %% ../../nbs/api/utilities/basic.ipynb
def filter_out_args(
    fnc:Callable, # Function to test keyword arguments against
    **kwargs      # Keyword arguments to test
)->dict:          # Keyword arguments not defined in signature of `fnc` 
    """Return only keyword arguments not defined in signature of function `fnc`."""
    return {k: v for k, v in kwargs.items() if k not in inspect.signature(fnc).parameters}
