from _erg_result import is_ok
from _erg_range import Range
def in_operator(x, y):
if type(y) == type:
if isinstance(x, y):
return True
elif is_ok(y.try_new(x)):
return True
return False
elif (issubclass(type(y), list) or issubclass(type(y), set)) \
and (type(y[0]) == type or issubclass(type(y[0]), Range)):
type_check = in_operator(x[0], y[0])
len_check = len(x) == len(y)
return type_check and len_check
elif issubclass(type(y), dict) and issubclass(type(next(iter(y.keys()))), type):
type_check = True len_check = len(x) >= len(y)
return type_check and len_check
else:
return x in y