# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/92_ares.ipynb.

# %% auto 0
__all__ = ['aremap', 'areinstances', 'aretype', 'aresame', 'arenone']

# %% ../nbs/92_ares.ipynb 4
from functools import partial
from typing import Iterable, TypeGuard

# %% ../nbs/92_ares.ipynb 5
from .atyp import G, GuardFunc
from .core import isiter, isint, isstr, isnone
from .wrap import makeguard
from .strs import isdig
from .alls import allmap, allnone

# %% ../nbs/92_ares.ipynb 7
def aremap(x, f: GuardFunc):
    '''Checks if all elements of `x` (and sub elements) passes TypeGuard `f`'''
    gmap = partial(allmap, f=f)
    return all(gmap(*e) if isiter(e) else gmap(e) for e in x)

def areinstances(x, t: G) -> TypeGuard[Iterable[G]]:
    '''Checks if all elements of `x` (and sub elements) are instances of `t`'''
    return aremap(x, makeguard(t))

# %% ../nbs/92_ares.ipynb 9
def aretype(x, t: G) -> TypeGuard[Iterable[G]]: 
    '''Checks if all elements of `x` are of type `t`'''
    return areinstances(x, t)

def aresame(x: Iterable) -> TypeGuard[Iterable[G]]:
    '''Checks if all elements of `x` are of the same type'''
    return aretype(x, type(x[0])) if (isiter(x) and len(x) > 0) else True

# %% ../nbs/92_ares.ipynb 11
def arenone(x) -> TypeGuard[Iterable[str]]: 
    '''Check if all elements of `x` are `None`'''
    return aremap(x, isnone)
