pydanny/cached-property

Support caching generators

Open

#100 opened on Jun 2, 2018

View on GitHub
 (6 comments) (0 reactions) (0 assignees)Python (79 forks)github user discovery
bugenhancementhelp wanted

Repository metrics

Stars
 (705 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Many times I'll have a function such as

def x():
    result = some_long_function_that_eventually_calculates_a_list()
    yield from (result.name for result in result)
    yield from (result.path for result in result)

I can't cache this function using regular cached_property because the generator will be exhausted. I want to calculate it once, then whenever it is being called again return the items I retrieved in the order I retrieved them.

Contributor guide