Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [lazy]

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.

0
votes
1answer
31 views

Singleton class to contain a DocumentClient instance, that can be overridden for testing

The DocumentClient is an object that accesses CosmosDb, but Microsoft recommends its kept as a ...
-1
votes
0answers
28 views

Mimick sequence generators and other coroutines

I wonder if this code can be considered as a lazy sequence generator or a build part of one, and if someone can find any problems with it. Could one implement other coroutine patterns this way? Is ...
3
votes
2answers
94 views

Lazy-loading iframes as they scroll into view

I'm working in a Tableau driven system, with large numbers of charts, I needed a way to reduce the strain of the initial load of our app. It's fairly simple, but wanted to ensure I accounted for every ...
23
votes
11answers
5k views

Own implementation of Lazy<T> object

The problem with the original Lazy in C# is that you have to put the initialization in the constructor if you want to refer to this. For me that is 95% of the ...
1
vote
1answer
56 views

Lazy prime counting function [closed]

I have written a simple snippet of code that implements a function that returns a list of primes up to a certain integer n. Assuming that this function could be ...
-1
votes
1answer
49 views

Shorthand private field caching of public property [closed]

I'm caching the value of a configuration object in a private field: ...
18
votes
8answers
2k views

Counting elements meeting a predicate in an enumerable without iterating the entire sequence

I was reading this question, and the answer that mentioned streams, and a thought had occurred to me. In many cases (at least in my usage) I want to determine if a sequence (or ...
4
votes
1answer
89 views

Lazy lists with transformations, using generators & iterators

I built this very-basic lazy list (I'll add more methods as I need them). You provide it an array, a generator or any iterator. It creates a lazy list, which lets you run a pipeline of transformations ...
8
votes
2answers
482 views

Lazy split and semi-lazy split

Sometimes I need to be able to split data into chunks, and so something like str.split would be helpful. This comes with two downsides: Input has to be strings You ...
3
votes
1answer
54 views

Python JIT container type

This is a follow on from this review. Where I am attempting to improve the performance of my rest client. I have created an container type (as suggested in my previous post) that lazily instantiates ...
1
vote
0answers
103 views

F# Operation Framework (Railway-Oriented Programming + Task/Async/Lazy)

I recently published the initial version of what is effectively my first open-source software package, a Railway-Oriented Programming Framework for F# that encapsulates Tasks, Async Workflows, and ...
7
votes
1answer
1k views

ResettableLazy<T>: a resettable version of .NET Lazy<T>

I implemented a resettable version of .NET Lazy (context: mostly to use it in a MemoryCache for auto refresh purposes on item expiration) This is a very naive implementation and I am pretty sure ...
3
votes
1answer
126 views

Efficiently determine every factor of a given natural number

It's not hard to find all of the factors of a given natural number. Below is a pretty fast python function that can do just that: (Modified version of Steinar Lima's function, https://stackoverflow....
3
votes
1answer
208 views

Selection algorithm using merge sort and IEnumerable

For educational purposes, I wrote a selection algorithm based on a Merge sort. I would like to improve performance. ...
3
votes
1answer
268 views

Lazy, functional streams library for Node.js

I’ve written a small library that implements lazy streams in (ES2016) JavaScript for use in Node.js. The library could work in the browser as well with some minor modifications, but that isn’t ...
5
votes
1answer
623 views

Singletons with eager and lazy instantiation

I've found more than one implementation of the Singleton Pattern in Java (more like 5-6). I want to know if both of the following snippets of code (written by me) are valid implementations of ...
1
vote
1answer
60 views

Class to help dealing with files, with lazy properties

I have the following class to help me deal with files: File class: ...
2
votes
2answers
1k 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 ...
1
vote
0answers
43 views

Lazily load permissions from database in multithreading environment

I would like to get the feedback about this code: ...
5
votes
2answers
149 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, ...
3
votes
1answer
455 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
407 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
847 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
293 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. ...
5
votes
1answer
983 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
2answers
4k 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
141 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
322 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 ...
8
votes
1answer
198 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
1k 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 ...
3
votes
3answers
3k 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
242 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
181 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 ...
2
votes
1answer
1k 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
834 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
1k 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. ...
3
votes
2answers
5k views

Flatten a tree to a collection of nodes

I have implemented simple tree class as follows: ...
2
votes
1answer
2k views

Python lazy dictionary

Here is a lazy dictionary with test cases. ...
1
vote
2answers
135 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
632 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
179 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
249 views

Converting an array-returning function to a lazy evaluator

Take a look at the following function: ...
4
votes
1answer
421 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
166 views

Calculating Fibonnaci sequence lazily

Implementation: ...
2
votes
1answer
73 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
990 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 ...
3
votes
1answer
1k 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
859 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
164 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
624 views

Recursive flatten with lazy evaluation iterator

I'm trying to rewrite this: ...