Java streams lazy vs fusion vs short-circuiting

As for fusion. Let’s imagine here’s a map operation: .map(x -> x.squash()) It’s stateless and it just transforms any input according to the specified algorithm (in our case squashes them). Now the filter operation: .filter(x -> x.getColor() != YELLOW) It’s also stateless and it just removes some elements (in our case yellow ones). Now let’s … Read more

caching the result from a [n async] factory method iff it doesn’t throw

Does this get anywhere near your requirements? The behaviour falls somewhere between ExecutionAndPublication and PublicationOnly. While the initializer is in-flight all calls to Value will be handed the same task (which is cached temporarily but could subsequently succeed or fail); if the initializer succeeds then that completed task is cached permanently; if the initializer fails … Read more

Lazy evaluation in Python

The object returned by range() (or xrange() in Python2.x) is known as a lazy iterable. Instead of storing the entire range, [0,1,2,..,9], in memory, the generator stores a definition for (i=0; i<10; i+=1) and computes the next value only when needed (AKA lazy-evaluation). Essentially, a generator allows you to return a list like structure, but … Read more