def __init__(self, f, args=None, kwds=None, name=None, category=None, cache=False): """ TESTS:: sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator sage: S = EnumeratedSetFromIterator(xsrange, (1,200,-1), category=FiniteEnumeratedSets()) sage: TestSuite(S).run() """ if category is not None: Parent.__init__(self, facade = True, category = category) else: Parent.__init__(self, facade = True, category = EnumeratedSets()) if name is not None: self.rename(name) self._func = f if args is not None: self._args = args if kwds is not None: self._kwds = kwds if cache: self._cache = lazy_list(iter(self._func( *getattr(self, '_args', ()), **getattr(self, '_kwds', {}))))
def clear_cache(self): r""" Clear the cache. EXAMPLES:: sage: from itertools import count sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator sage: E = EnumeratedSetFromIterator(count, args=(1,), cache=True) sage: e1 = E._cache sage: e1 lazy list [1, 2, 3, ...] sage: E.clear_cache() sage: E._cache lazy list [1, 2, 3, ...] sage: e1 is E._cache False """ if hasattr(self, "_cache"): self._cache = lazy_list(iter(self._func(*getattr(self, "_args", ()), **getattr(self, "_kwds", {}))))
def clear_cache(self): r""" Clear the cache. EXAMPLES:: sage: from itertools import count sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator sage: E = EnumeratedSetFromIterator(count, args=(1,), cache=True) sage: e1 = E._cache sage: e1 lazy list [1, 2, 3, ...] sage: E.clear_cache() sage: E._cache lazy list [1, 2, 3, ...] sage: e1 is E._cache False """ if hasattr(self, '_cache'): self._cache = lazy_list(iter(self._func( *getattr(self, '_args', ()), **getattr(self, '_kwds', {}))))