PK!c..all_purpose_set/__init__.pyfrom .index import ApSet __all__ = ["ApSet"] PK!%pall_purpose_set/fns/__init__.pyfrom .forEach import forEach from .isLaden import isLaden from .joinWith import joinWith from .map_ import map_ from .passThrough import passThrough from .raise_ import raise_ __all__ = ["forEach", "isLaden", "joinWith", "map_", "passThrough", "raise_"] PK!*all_purpose_set/fns/decorators/__init__.pyPK![`)gEE/all_purpose_set/fns/decorators/argIsCallable.pyfrom inspect import signature import wrapt @wrapt.decorator def argIsCallable(fn, _instance, args, kwargs): if not callable(args[0]): argName = list(signature(fn).parameters)[0] fnName = fn.__name__ raise ValueError(f"{fnName} requires {argName} to be callable") return fn(*args, **kwargs) PK!waII,all_purpose_set/fns/decorators/argIsClass.pyfrom inspect import isclass, signature import wrapt @wrapt.decorator def argIsClass(fn, _instance, args, kwargs): if not isclass(args[0]): argName = list(signature(fn).parameters)[0] fnName = fn.__name__ raise ValueError(f"{fnName} requires {argName} to be a class") return fn(*args, **kwargs) PK!1all_purpose_set/fns/decorators/argIsListOfType.pyfrom ordered_set import OrderedSet import wrapt from ..internal.discardWhen import discardWhen from ..internal.get import get from ..internal.getArgName import getArgName from ..internal.isLaden import isLaden from ..internal.isType import isType from ..internal.joinWith import joinWith from ..internal.map_ import map_ from ..internal.passThrough import passThrough from ..internal.raise_ import raise_ from ..internal.sort import sort from ..internal.toType import toType def argIsListOfType(aType): @wrapt.decorator def wrapper(fn, _instance, args, kwargs): typePassed = type(args[0]) fnName = fn.__name__ typeName = aType.__name__ if typePassed is not list: argName = getArgName(fn) raise_( ValueError, f"""\ {fnName} requires {argName} to have the type list type passed: {typePassed.__name__} """, ) invalidTypes = discardWhen(isType(aType))(args[0]) if isLaden(invalidTypes): argName = getArgName(fn) invalidTypeNames = passThrough( invalidTypes, [ map_(toType), OrderedSet, list, map_(get("__name__")), sort, joinWith(", "), ], ) raise_( ValueError, f"""\ {fnName} requires {argName} to be a list of {typeName} invalid types passed: {invalidTypeNames} """, ) return fn(*args, **kwargs) return wrapper PK!)ʋ+all_purpose_set/fns/decorators/argIsType.pyfrom inspect import signature from ..internal.raise_ import raise_ import wrapt def argIsType(aType): @wrapt.decorator def wrapper(fn, _instance, args, kwargs): typePassed = type(args[0]) if typePassed is not str: argName = list(signature(fn).parameters)[0] fnName = fn.__name__ typeName = aType.__name__ raise_( ValueError, f"""\ {fnName} requires {argName} to have the type {typeName} type passed: {typePassed.__name__} """, ) return fn(*args, **kwargs) return wrapper PK!`c??all_purpose_set/fns/forEach.py# ------- # # Imports # # ------- # from types import SimpleNamespace from .internal.makeGenericCallFn import makeGenericCallFn from .internal.getTypedResult import getTypedResult from .decorators.argIsCallable import argIsCallable # ---- # # Main # # ---- # @argIsCallable def forEach(fn): fnName = forEach.__name__ callFn = makeGenericCallFn(fn, 3, fnName) def forEach_inner(collection): typedForEach = getTypedResult(collection, typeToForEach, fnName) return typedForEach(callFn, collection) return forEach_inner # ------- # # Helpers # # ------- # def forEach_dict(callFn, aDict): for key, val in aDict.items(): callFn(val, key, aDict) return aDict def forEach_list(callFn, aList): for idx, el in enumerate(aList): callFn(el, idx, aList) return aList def forEach_simpleNamespace(callFn, aSimpleNamespace): forEach_dict(callFn, aSimpleNamespace.__dict__) return aSimpleNamespace typeToForEach = { dict: forEach_dict, list: forEach_list, SimpleNamespace: forEach_simpleNamespace, } PK!(all_purpose_set/fns/internal/__init__.pyPK!F+all_purpose_set/fns/internal/discardWhen.py# ------- # # Imports # # ------- # from .getTypedResult import getTypedResult from .makeGenericCallFn import makeGenericCallFn from ..decorators.argIsCallable import argIsCallable # ---- # # Main # # ---- # @argIsCallable def discardWhen(predicate): fnName = discardWhen.__name__ shouldDiscard = makeGenericCallFn(predicate, 3, fnName) def discardWhen_inner(collection): typedDiscardWhen = getTypedResult(collection, typeToDiscardWhen, fnName) return typedDiscardWhen(shouldDiscard, collection) return discardWhen_inner # ------- # # Helpers # # ------- # def discardWhen_list(shouldDiscard, aList): result = [] for idx, el in enumerate(aList): if not shouldDiscard(el, idx, aList): result.append(el) return result def discardWhen_dict(shouldDiscard, aDict): result = {} for key, val in aDict.items(): if shouldDiscard(val, key, aDict): result[key] = val return result typeToDiscardWhen = {list: discardWhen_list, dict: discardWhen_dict} PK!ss#all_purpose_set/fns/internal/get.pydef get(attrName): def get_inner(something): return getattr(something, attrName) return get_inner PK!)jj*all_purpose_set/fns/internal/getArgName.pyfrom inspect import signature def getArgName(fn, idx=0): return list(signature(fn).parameters)[idx] PK!X.all_purpose_set/fns/internal/getFnSignature.pyfrom inspect import signature from .raise_ import raise_ def getFnSignature(fn, callerName): try: return signature(fn) except Exception as e: raise_( ValueError, f"""\ '{callerName}' is unable to get the signature of the passed callable callable passed: {fn.__name__} one reason this could occur is the callable is written in c (e.g. the builtin 'str' callable). """, fromException=e, ) PK!k6all_purpose_set/fns/internal/getNumPositionalParams.py# ------- # # Imports # # ------- # from inspect import Parameter from math import inf from .getFnSignature import getFnSignature from .iif import iif # ---- # # Init # # ---- # _nonVarPositionalParamKinds = { Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD, } # ---- # # Main # # ---- # # # Returns a tuple # numRequired: number of required positional params # numAllowed: number of allowed positional params # def getNumPositionalParams(fn, callerName): sig = getFnSignature(fn, callerName) numAllowed = iif(_hasVarPositionalParam(sig), inf, 0) numRequired = 0 for p in sig.parameters.values(): if p.kind in _nonVarPositionalParamKinds: numAllowed += 1 if p.default is Parameter.empty: numRequired += 1 return (numRequired, numAllowed) # ------- # # Helpers # # ------- # def _hasVarPositionalParam(sig): for p in sig.parameters.values(): if p.kind is Parameter.VAR_POSITIONAL: return True PK!w<.all_purpose_set/fns/internal/getTypedResult.py# # README # - I'm not sure what to call this. Its purpose is to centralize the type # validation, minimizing copy/paste. # # ------- # # Imports # # ------- # from .raise_ import raise_ from .get import get # ---- # # Init # # ---- # getName = get("__name__") # # we need a unique object here to ensure the 'typeToSomething' doesn't lead us # to a 'None' value # nothing = object() # ---- # # Main # # ---- # def getTypedResult(value, typeToSomething, fnName): valueType = type(value) result = typeToSomething.get(valueType, nothing) if _isSomething(result): return result supportedTypes = ", ".join(map(getName, typeToSomething.keys())) raise_( ValueError, f"""\ {fnName} doesn't support the type '{valueType.__name__}' supported types: {supportedTypes} """, ) # ------- # # Helpers # # ------- # def _isSomething(x): return x is not nothing PK!;||#all_purpose_set/fns/internal/iif.pydef iif(condition, whenTruthy, whenFalsey): if condition: return whenTruthy else: return whenFalsey PK!ws{33'all_purpose_set/fns/internal/isLaden.pydef isLaden(aList): return len(aList) is not 0 PK!Ȋ0all_purpose_set/fns/internal/isOnlyWhitespace.pyimport re onlyWhitespaceRe = re.compile(r"\s*$") def isOnlyWhitespace(aString): return onlyWhitespaceRe.match(aString) is not None PK!f&all_purpose_set/fns/internal/isType.pyfrom inspect import isclass def isType(aType): if not isclass(aType): raise ValueError("isType requires argument 'aType' to pass isclass") def isType_inner(something): return type(something) is aType return isType_inner PK!v_R*++(all_purpose_set/fns/internal/joinWith.py# ------- # # Imports # # ------- # from ordered_set import OrderedSet from .getTypedResult import getTypedResult # ---- # # Main # # ---- # def joinWith(separator): def joinWith_inner(collection): typedJoinWith = getTypedResult(collection, typeToJoinWith, "joinWith") return typedJoinWith(separator, collection) return joinWith_inner # ------- # # Helpers # # ------- # def joinWith_iterable(separator, aList): return separator.join(aList) typeToJoinWith = {list: joinWith_iterable, OrderedSet: joinWith_iterable} PK!K*all_purpose_set/fns/internal/makeCallFn.py# ------- # # Imports # # ------- # from math import inf from .returnFirstArgument import returnFirstArgument as identity from .getNumPositionalParams import getNumPositionalParams # ---- # # Main # # ---- # def makeCallFn(fn, callerName, *, modifyResult=identity): (_, allowed) = getNumPositionalParams(fn, callerName) if allowed is inf: return lambda *args, **kwargs: modifyResult(fn(*args, **kwargs)) else: return lambda *args, **kwargs: modifyResult( fn(*args[:allowed], **kwargs) ) PK!T-1all_purpose_set/fns/internal/makeGenericCallFn.py# ------- # # Imports # # ------- # from math import inf from .getNumPositionalParams import getNumPositionalParams from .raise_ import raise_ # ---- # # Main # # ---- # def makeGenericCallFn(fn, maxParams, callerName): required, allowed = getNumPositionalParams(fn, callerName) if allowed is inf: allowed = maxParams if required > maxParams: raise_( ValueError, f""" {callerName} can only take functions with up to {maxParams} positional params. The function '{fn.__name__}' requires {required} """, ) return lambda *args, **kwargs: fn(*args[:allowed], **kwargs) PK!G~$all_purpose_set/fns/internal/map_.py# ------- # # Imports # # ------- # from .makeGenericCallFn import makeGenericCallFn from .getTypedResult import getTypedResult from ..decorators.argIsCallable import argIsCallable # ---- # # Main # # ---- # @argIsCallable def map_(mapperFn): fnName = map_.__name__ callMapperFn = makeGenericCallFn(mapperFn, 3, fnName) def map_inner(collection): typedMap = getTypedResult(collection, typeToMap, fnName) return typedMap(callMapperFn, collection) return map_inner # ------- # # Helpers # # ------- # def map_list(callMapperFn, aList): result = [] for idx, el in enumerate(aList): result.append(callMapperFn(el, idx, aList)) return result typeToMap = {list: map_list} PK!yy+all_purpose_set/fns/internal/passThrough.pyfrom .reduce import reduce def passThrough(arg, fnList): return reduce(lambda result, fn: fn(result), arg)(fnList) PK!W&all_purpose_set/fns/internal/raise_.pyfrom tedent import tedent from .isOnlyWhitespace import isOnlyWhitespace import os def raise_(errorClass, message, *, fromException=None): allLines = message.split(os.linesep) if isOnlyWhitespace(allLines[0]) and isOnlyWhitespace(allLines[-1]): message = tedent(message) err = errorClass(message) if fromException is None: raise err else: raise err from fromException PK!Et&all_purpose_set/fns/internal/reduce.py# ------- # # Imports # # ------- # from .makeGenericCallFn import makeGenericCallFn from .getTypedResult import getTypedResult from ..decorators.argIsCallable import argIsCallable # ---- # # Main # # ---- # @argIsCallable def reduce(fn, initial): reducerFn = makeGenericCallFn(fn, 4, "reduce") def reduce_inner(collection): typedReduce = getTypedResult(collection, typeToReduce, "reduce") return typedReduce(reducerFn, initial, collection) return reduce_inner # ------- # # Helpers # # ------- # def reduce_list(reducerFn, initial, aList): result = initial for idx, el in enumerate(aList): result = reducerFn(result, el, idx, aList) return result typeToReduce = {list: reduce_list} PK!pjj3all_purpose_set/fns/internal/returnFirstArgument.pyfrom .iif import iif def returnFirstArgument(*args, **kwargs): return iif(len(args), args[0], None) PK!\xx/all_purpose_set/fns/internal/sanitizeAscDesc.pyfrom .raise_ import raise_ ascDescSet = {"asc", "desc"} def sanitizeAscDesc(ascOrDesc): sanitized = ascOrDesc.lower() if sanitized not in ascDescSet: raise_( ValueError, f""" ascOrDesc must be either 'asc' or 'desc' (case insensitive) value given: {ascOrDesc} """, ) return sanitized PK!0oo$all_purpose_set/fns/internal/sort.py# ------- # # Imports # # ------- # from .getTypedResult import getTypedResult # ---- # # Main # # ---- # def sort(collection): typedSort = getTypedResult(collection, typeToSort, "sort") return typedSort(collection) # ------- # # Helpers # # ------- # def sort_viaSorted(something): return sorted(something) typeToSort = {list: sort_viaSorted} PK!V;22&all_purpose_set/fns/internal/toType.pydef toType(something): return type(something) PK!X33all_purpose_set/fns/isLaden.pyfrom .internal.isLaden import isLaden # noqa f401 PK!955all_purpose_set/fns/joinWith.pyfrom .internal.joinWith import joinWith # noqa f401 PK!}--all_purpose_set/fns/map_.pyfrom .internal.map_ import map_ # noqa f401 PK!F;;"all_purpose_set/fns/passThrough.pyfrom .internal.passThrough import passThrough # noqa f401 PK!(11all_purpose_set/fns/raise_.pyfrom .internal.raise_ import raise_ # noqa f401 PK!XZ_ all_purpose_set/index.py# ------- # # Imports # # ------- # from ordered_set import OrderedSet from .fns import forEach, raise_ # ---- # # Main # # ---- # class ApSet: def __init__(self, aList=[]): validateInput(aList) # # _orderedElements holds a set of tuples # (hashable: boolean, idOrElement) where idOrElement is the id of the # element when hashable is false. Likewise when hashable is true, # idOrElement is the actual element. # self._orderedElements = OrderedSet() self._hashableElements = set() # # because this holds non-hashable elements, it needs to be a dict of # id(element) -> element # self._nonHashableElements = {} forEach(self._addElement)(aList) def _addElement(self, element): try: self._hashableElements.add(element) self._orderedElements.add((True, element)) except: self._nonHashableElements[id(element)] = element self._orderedElements.add((False, id(element))) return self def __contains__(self, element): return self.has(element) def __iter__(self): return ApSetIterator(self) def __len__(self): return len(self._orderedElements) def add(self, element): return self._addElement(element) def clear(self): self._hashableElements.clear() self._nonHashableElements.clear() self._orderedElements.clear() return self def has(self, element): try: return element in self._hashableElements except: return id(element) in self._nonHashableElements def remove(self, element): elementRemoved = False try: if element in self._hashableElements: elementRemoved = True self._orderedElements.discard((True, element)) self._hashableElements.remove(element) except: if id(element) in self._nonHashableElements: elementRemoved = True self._orderedElements.discard((False, id(element))) del self._nonHashableElements[id(element)] if not elementRemoved: raise KeyError( f"the element '{str(element)}' does not exist in ApSet" ) return self class ApSetIterator: def __init__(self, apSetInst): self._inst = apSetInst self._orderedElementsIterator = iter(apSetInst._orderedElements) def __next__(self): hashable, elementOrId = next(self._orderedElementsIterator) if hashable: return elementOrId else: return self._inst._nonHashableElements[elementOrId] # ------- # # Helpers # # ------- # def validateInput(aList): if not isinstance(aList, list): raise_( ValueError, f""" aList is not an instance of list type given: {type(aList)} """, ) PK!4 Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHAT THE FUCK YOU WANT TO BUT IT'S NOT MY FAULT PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. You just DO WHAT THE FUCK YOU WANT TO. 1. Do not hold the author(s), creator(s), developer(s) or distributor(s) liable for anything that happens or goes wrong with your use of the work. PK!HڽTU%all_purpose_set-0.1.3.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HYP (all_purpose_set-0.1.3.dist-info/METADATAVmo6_q m6#Р bZDl$Q%(۱b@}^{ثLyiS eE4V%HE\76c>Z__EӦ,m4$ϕ47ɕռ`RUFⵀ ..zgJku sk78:}3罹<23U]p>+q4l|n.s].t)TPu/9F[ve MdwUiӷū5wV胪Lȃ^=Wv~@fl9I /B O3*z4, Li `l<\;L9;O'ԨzY˶ֻrV#eYL\9ըtҴ3ƖJ2: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˵[S%7)`IaPK!c..all_purpose_set/__init__.pyPK!%pgall_purpose_set/fns/__init__.pyPK!*all_purpose_set/fns/decorators/__init__.pyPK![`)gEE/all_purpose_set/fns/decorators/argIsCallable.pyPK!waII,}all_purpose_set/fns/decorators/argIsClass.pyPK!1all_purpose_set/fns/decorators/argIsListOfType.pyPK!)ʋ+ all_purpose_set/fns/decorators/argIsType.pyPK!`c??all_purpose_set/fns/forEach.pyPK!([all_purpose_set/fns/internal/__init__.pyPK!F+all_purpose_set/fns/internal/discardWhen.pyPK!ss#all_purpose_set/fns/internal/get.pyPK!)jj*all_purpose_set/fns/internal/getArgName.pyPK!X.lall_purpose_set/fns/internal/getFnSignature.pyPK!k6all_purpose_set/fns/internal/getNumPositionalParams.pyPK!w<. all_purpose_set/fns/internal/getTypedResult.pyPK!;||# $all_purpose_set/fns/internal/iif.pyPK!ws{33'$all_purpose_set/fns/internal/isLaden.pyPK!Ȋ0B%all_purpose_set/fns/internal/isOnlyWhitespace.pyPK!f&&all_purpose_set/fns/internal/isType.pyPK!v_R*++(Z'all_purpose_set/fns/internal/joinWith.pyPK!K*)all_purpose_set/fns/internal/makeCallFn.pyPK!T-11,all_purpose_set/fns/internal/makeGenericCallFn.pyPK!G~$!/all_purpose_set/fns/internal/map_.pyPK!yy+?2all_purpose_set/fns/internal/passThrough.pyPK!W&3all_purpose_set/fns/internal/raise_.pyPK!Et&4all_purpose_set/fns/internal/reduce.pyPK!pjj38all_purpose_set/fns/internal/returnFirstArgument.pyPK!\xx/8all_purpose_set/fns/internal/sanitizeAscDesc.pyPK!0oo$:all_purpose_set/fns/internal/sort.pyPK!V;22&C<all_purpose_set/fns/internal/toType.pyPK!X33<all_purpose_set/fns/isLaden.pyPK!955(=all_purpose_set/fns/joinWith.pyPK!}--=all_purpose_set/fns/map_.pyPK!F;;">all_purpose_set/fns/passThrough.pyPK!(11{>all_purpose_set/fns/raise_.pyPK!XZ_ >all_purpose_set/index.pyPK!4