Lazy evaluation refers to a variety of concepts that seek to avoid evaluation of an expression unless its value is needed, and to share the results of evaluation of an expression among all uses of its, so that no expression need be evaluated more than once.
1
vote
1answer
37 views
Class to help dealing with files, with lazy properties
I have the following class to help me deal with files:
File class:
...
1
vote
2answers
120 views
Using Concurrent Dictionary and Lazy<T> to cache expensive query results and only run query once in a threadsafe manner
Ok, so I'm querying a webservice. This webservice is slow with multiple o's. I want to cache the results of the query, because I only want to query on a given set of parameters once during my ...
0
votes
0answers
39 views
Lazily load permissions from database in multithreading environment
I would like to get the feedback about this code:
...
5
votes
2answers
94 views
Snoozy: A lazy reevaluation upon get
I would appreciate critique and comments in regards of thread-safety on a basic type I'm trying to create.
In C#, the Lazy<T> type is initialized only once, ...
2
votes
1answer
104 views
Optionally Lazy Parameters
Inspired by Swift's @autoclosure feature, I tried writing a brief C++-14 header that permits "optionally" lazy parameters (by "lazy" I mean ...
4
votes
2answers
102 views
Python lazy dict with iterator in constructor
This question began as an off-topic answer to this question, but the code here serves a different goal.
I wrote the following class for the purpose of populating a dict on demand from an iterator. ...
0
votes
1answer
114 views
C++ lazy constructor
I'm implementing a lazy constructor in C++. The goal is that for a type T, lazy<T>(args...) returns a callable object ...
5
votes
1answer
133 views
Lazy String splitter in C++
I created a string splitter in C++. It splits a string in a lazy fashion and makes use of forward iterators to sequentially supply the next token from the string until it runs out of tokens.
...
4
votes
1answer
215 views
Lazy prime number generator
There are multiple Project Euler problems (e.g. 7, 10) that deal with prime numbers. I decided make a reusable solution that could be used for most of them.
I wrote a method to generate an infinite* ...
3
votes
1answer
362 views
Finding a Cartesian product of multiple lists
I came up with an extension method to find a Cartesian product of multiple IEnumerable sets. I was able to achieve lazy enumeration via ...
1
vote
0answers
54 views
Understanding lazy sequence in Clojure
In order to understand how the lazy sequences work in Clojure, I decided to implement the quick-sort example from the "The Joy of Clojure, Second Edition" book simulating lazy sequences in Java. Of ...
3
votes
0answers
58 views
Lazy WebAPI object
I am working to design an object which would abstract away the use of a WebAPI. I want the developer to be able to use these objects as if they are using a traditional API.
My core problem is how to ...
10
votes
1answer
102 views
Caching data by using the result of first running operation
My code handles concurrent requests by waiting for the result of an already running operation. Requests for data may come in simultaneously with same/different credentials (including empty credentials)...
11
votes
3answers
608 views
Poor man's lazy evaluation in Java 8
I have an class that cheaply imitates a lazy evaluation scheme. The class is for representing a file and additionally providing meta data on the file. Some of the meta-data can be expensive to ...
4
votes
3answers
836 views
Unity Lazy Resolve Implementation
I have been using Microsoft.Unity as my container and have decided that the approach for a lazy implementation causes too much rework. Each time you decide to swap ...
7
votes
2answers
161 views
Reading lines from a file in random order
I originally wrote this as an answer to a question on Stack Overflow, but it turned out so nicely that I decided to post it here to see if I can make it even better.
...
4
votes
1answer
100 views
Clojure word count
I'm fairly new to Clojure and looking to improve my use of the proper idioms, and make my code more readable. Here's the problem:
Read from standard input and produce the count of each word to ...
1
vote
1answer
345 views
Early-termination foldLeft for Scala Streams
The foldRight and foldLeft methods for Scala Streams cannot terminate early, so here is my ...
2
votes
2answers
197 views
Date formatters, lazily instantiated once
I would like to create two date formatters only on first call. In Objective-C I would use dispatch_once() but now working in Swift. Am I doing it correctly? My code ...
2
votes
3answers
742 views
Loading visible images
I am using this code to get images to load only if they are visible. However, it seems to be slow with thousands of images, even if they are not rendered.
...
2
votes
2answers
2k views
2
votes
1answer
1k views
1
vote
2answers
90 views
Lazy properties for the angle and length of a line segment
The code below shows the pattern I use to manage properties in my classes when I have the following requirements:
Some properties are slow to calculate and are rarely used, so I want them to be lazy
...
11
votes
2answers
405 views
Lazy String.Split
C#'s String.Split method comes from C# 2.0, and lazy operations weren't a feature back then. The task is to split a string according to a (single) separator. Doing ...
3
votes
1answer
95 views
SICP streams in C++
To brush up on my C++ chops, I've implemented a toy version of "SICP Streams", which behave like lists with one twist: the first element of the list is always available, the rest of the list is stored ...
3
votes
1answer
146 views
Converting an array-returning function to a lazy evaluator
Take a look at the following function:
...
4
votes
1answer
261 views
Lazy Load for multiple entities at a time
We have a system with a non standard database solution. All trips to the DB are rather expensive. We cannot use entity framework.
Currently our lazy loading is on an entity by entity basis. So if I ...
7
votes
4answers
156 views
2
votes
1answer
62 views
Perfect elimination ordering and high memory usage
The following code calculates a perfect
elimination ordering in a special case in Haskell.
I am less worried about its correctness than
its high use of memory. The following code runs
out of memory ...
7
votes
3answers
894 views
Lazily Load CSS and JS
I have written this piece of JS and CSS loading code and I would like some advice on it. Anything some of the JavaScript gurus could possibly point out would be much appreciated. The code works, but I ...
2
votes
1answer
680 views
AsyncLazy disposal
I've made this extension method. Its purpose is to trigger the disposal of a value, stored in a Nito.AsyncEx AsyncLazy, as authored by @StephenCleary.
Is this an ...
7
votes
2answers
573 views
Generic cached value class mimicking Lazy<T>
Before I wrote this I searched and found a number of solutions that make use of a caching provider to handle a set of items. I felt that was too cumbersome of an approach and set out to create a class ...
3
votes
2answers
144 views
Azure cache getoradd (without locking)
Inspired by the non-locking implementation proposed in this post, the following code is an attempt to (about) do the same using the azure cache. As I'm totally green on the Azure cache I'd appreciate ...
4
votes
2answers
261 views
14
votes
2answers
3k views
1
vote
1answer
907 views
Lazy loading with __get
I have my own PHP MVC framework that I'm iteratively developing (i.e. adding a feature when I have the time). I'm trying to keep it to the best practices I can, while still adding the most in terms of ...
2
votes
2answers
244 views
Are there any issues in this `Lazy` implementation?
I have written following small utility to abstract away the lazy initialization logic. (I tend to use lazy variables quite often.)
Are there any issues in this implementation?
...
2
votes
2answers
1k views
Lazy class instantiation in Python
I've written some class which allows me to derive from it to make objects lazy-instantiated. Do you see notational improvements or maybe even cases where this method might not work (multiple ...
4
votes
1answer
252 views
Lazy look and say sequence
I have been solving a set of online Clojure problems. One of them involves the look and say sequence.
...