# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/91_lens.ipynb.

# %% auto 0
__all__ = ['islenn', 'islen1', 'islen2', 'islen3', 'islen4', 'hasn', 'has1', 'has2', 'has3', 'has4', 'isnints', 'is2ints',
           'is3ints', 'is4ints', 'ischr', 'ischar']

# %% ../nbs/91_lens.ipynb 4
from typing import TypeGuard
from typing import Iterable, Optional

# %% ../nbs/91_lens.ipynb 5
from .core import isiter, isstr
from .alls import isints

# %% ../nbs/91_lens.ipynb 7
def islenn(a, n: int = 1) -> TypeGuard[Iterable]:
    '''Check if `a` has exactly `n` elements.'''
    return len(a) == n

def islen1(a) -> TypeGuard[Iterable]:
    '''Check if `a` has exactly `1` elements.
    
    See Also
    --------
    islenn : check if arguments contain at n elements.
    '''
    return islenn(a, 1)

def islen2(a) -> TypeGuard[Iterable]:
    '''Check if `a` has exactly `2` elements.
    
    See Also
    --------
    islenn : check if arguments contain at n elements.
    '''
    return islenn(a, 2)

def islen3(a) -> TypeGuard[Iterable]:
    '''Check if `a` has exactly `3` elements.
    
    See Also
    --------
    islenn : check if arguments contain at n elements.
    '''
    return islenn(a, 3)

def islen4(a) -> TypeGuard[Iterable]:
    '''Check if `a` has exactly `4` elements.
    
    See Also
    --------
    islenn : check if arguments contain at n elements.
    '''
    return islenn(a, 4)


# %% ../nbs/91_lens.ipynb 8
def hasn(a, n: int = 1) -> TypeGuard[Iterable]:
    '''Check if `a` contain at least `n` elements.'''
    return isiter(a) and len(a) >= n

def has1(a) -> TypeGuard[Iterable]: 
    '''Check if `a` contain at least `1` elements.
    
    See Also
    --------
    hasn : check if `a` contain at least `n` elements.
    '''
    return hasn(a, 1)

def has2(a) -> TypeGuard[Iterable]: 
    '''Check if `a` contain at least `2` elements.
    
    See Also
    --------
    hasn : check if `a` contain at least `n` elements.
    '''
    return hasn(a, 2)

def has3(a) -> TypeGuard[Iterable]: 
    '''Check if `a` contain at least `3` elements.
    
    See Also
    --------
    hasn : check if `a` contain at least `n` elements.
    '''
    return hasn(a, 3)

def has4(a) -> TypeGuard[Iterable]: 
    '''Check if `a` contain at least `4` elements.
    
    See Also
    --------
    hasn : check if `a` contain at least `n` elements.
    '''
    return hasn(a, 4)


# %% ../nbs/91_lens.ipynb 9
def isnints(a, n: int) -> TypeGuard[Iterable[int]]: 
    '''Check if `a` contains exactly `n` `int`s.'''
    return isints(a) and islenn(a, n)

def is2ints(a) -> TypeGuard[Iterable[int]]:
    '''Check if `a` contain exactly 2 `int`s.
    
    See Also
    --------
    isnints : Check if `a` contains exactly `n` `int`s.
    '''
    return isnints(a, 2)

def is3ints(a) -> TypeGuard[Iterable[int]]: 
    '''Check if `a` contain exactly 3 `int`s.
    
    See Also
    --------
    isnints : Check if `a` contains exactly `n` `int`s.
    '''
    return isnints(a, 3)

def is4ints(a) -> TypeGuard[Iterable[int]]: 
    '''Check if `a` contain exactly 4 `int`s.
    
    See Also
    --------
    isnints : Check if `a` contains exactly `n` `int`s.
    '''
    return isnints(a, 4)

# %% ../nbs/91_lens.ipynb 10
def ischr(s) -> TypeGuard[str]:
    '''Check if `s` is just a single character'''
    return isstr(s) and islenn(s, 1)

def ischar(s: str, char: Optional[str] = None) -> TypeGuard[str]:
    '''Checks if a `s` is just a single character or is the specific `char`.'''
    return isstr(s) and islenn(s, 1) and isstr(char) and s == char
