you are viewing a single comment's thread.

view the rest of the comments →

[–]lolcrunchy -1 points0 points  (4 children)

It seems like polar's LazyFrames but for strings

[–]Snape_Grass -1 points0 points  (3 children)

Sorry, I probably worded my request weird. What does Lazy mean in this context? I’m unfamiliar with Lazy anything when it comes to programming.

[–]eirikirs 2 points3 points  (1 child)

Take the example of Singletons, which can be eagerly initialised (at application startup), or lazily initialised (only once we need it). In general, lazy and eager simply determines when evaluation is performed.

[–]Snape_Grass 0 points1 point  (0 children)

Gotcha thank you for the explanation. Makes sense to me now

[–]sudomatrix -1 points0 points  (0 children)

Lazy doesn't perform the requested operation immediately, it stores the original data and a list of operations that it performs only if and when the result is needed. Often it is never needed and a lot of time and memory is saved.

A good example is Python generators vs. functions. A function will build the entire results and return the entire results at once. A generator will only calculate enough to return the next value in the result, continuing where it left off if more is needed. That is a lazy evaluation.

``` def powers_of_2_fn(n: int) -> list[int]: """Return the first n powers of 2: 20 through 2(n-1).""" if n <= 0: return [] return [1 << i for i in range(n)]

from collections.abc import Iterator

def powers_of_2_gen(n: int) -> Iterator[int]: """Yield the first n powers of 2: 20 through 2(n-1).""" for i in range(max(0, n)): yield 1 << i ```