Questions tagged [lazy-sequences]

Lazy sequences are sequences that are constructed as their members are accessed.

Lazy sequences are sequences that are constructed as their members are accessed.

For example, all haskell sequences are lazy because of the lazy semantics of the language; python's generators can also be considered lazy sequences.

273 questions
0
votes
0 answers

Questions on the lazyload method

I added the lazyload to the image tags. Saw the loading and then the actual image. I was shocked to see the code change (src, lazyloaded) when viewing the source code. Source code:
0
votes
1 answer

Should a doall Clojure function be used with a reduce call?

I have been using Clojure, ClojureScript, lein, shadow-cljs, re-frame, reagent, Emacs, and CIDER to work on a Clojure/ClojureScript dynamic web app project. I am new to Clojure. At some point in the codebase there is a big use of doall command…
Pedro Delfino
  • 2,421
  • 1
  • 15
  • 30
0
votes
1 answer

Can we improve upon this primes sieve code from SICP

A recent Q&A entry showcased the following primes generating code from SICP, using lazy streams: (define (sieve stream) (cons-stream (stream-car stream) (sieve (stream-filter (lambda (x) (not (divisible? x…
Will Ness
  • 70,110
  • 9
  • 98
  • 181
0
votes
2 answers

How to count the number of elements in an extremely large lazy seq?

I have the following (extremely large) lazy-seq: (def lazy-list (partition-all 100000 (take 10000000000000000000 (repeat 1)))) I want to count the number of elements in it, for which I am doing the following: (time (loop [ll lazy-list c…
Punit Naik
  • 515
  • 7
  • 26
0
votes
2 answers

How to utilize memory/performance when processing a big file in Clojure

How to utilize memory/performance when processing a large data set of time series data ? Size : ~3.2G Lines : ~54 million First few line of dataset {:ts 20200601040025269 :bid 107.526000 :ask 107.529000} {:ts 20200601040025370 :bid 107.525000 :ask…
madeinQuant
  • 1,721
  • 1
  • 18
  • 29
0
votes
0 answers

Recursive LazyList construction inside def gives error

If I write the following everything works as expected: object Working extends App { val whl: LazyList[Int] = 1 #:: 2 #:: 3 #:: whl (1 to 10) foreach {n => println(whl(n)) } } However, if I wrap my LazyList in a def: object NotWorking extends…
0
votes
1 answer

Faster/lazier way to evenly and randomly split m*n into n group (each has m elements) in python

I want to split m*n elements (e.g., 1, 2, ..., m*n) into n group randomly and evenly such that each group has m random elements. Each group will process k (k>=1) elements at one time from its own group and at the same speed (via some synchronization…
Daniel
  • 1,783
  • 2
  • 15
  • 25
0
votes
1 answer

Clojure, java.io.Writer f and lazy seq

Cant consume lazy-seq to write data to file, no matter what i using, "Stream closed" error raised every time. (ns logger.core (:gen-class) (:require [clojure.java.io :as io]) (:import java.util.Date java.util.TimeZone …
Hive
  • 3
  • 1
0
votes
1 answer

Generating a stream of all possible tuples from given streams using Scheme

I am trying to write a procedure stream-weighted-tuples that takes a weight procedure and any number of streams, to generate a stream of tuples. For instance, (stream-weighted-tuples (lambda (t) (+ (car t) (cadr t) (caddr t)) integers …
Jay Lee
  • 1,684
  • 1
  • 15
  • 27
0
votes
1 answer

How to turn a clojure lazy-seq of strings into separate strings?

I have a random amount of strings in a seq that I'm trying to "destructure"? into separate strings, while also dropping the last string in the seq. ("a" "b" "c") -> "a" "b" I tried a few things, and the closest I've got is with (apply str (drop-last…
J. Doe
  • 35
  • 1
  • 7
0
votes
1 answer

How to lazily evaluate a sequence by altering every alternate values in the sequence?

I have implemented a lazy infinite sequence function along with 3 functions called take,reduce,map. the take function is similar to Haskell's implementation where it takes a finite sequence from the infinite sequence given a finite value and the…
0
votes
1 answer

How do I access a lazy sequence with an index?

I noticed this behaviour regarding lazy sequences today: // filtered will be [2, 4, 6, 8] let filtered = [1,2,3,4,5,6,7,8].lazy.filter { $0 % 2 == 0 } print(filtered[2]) // expecting 6, but prints 3 I understand why it gives me 3. The subscript…
Sweeper
  • 213,210
  • 22
  • 193
  • 313
0
votes
2 answers

why is the time macro claiming a very short elapsed time for slow function call?

Was looking at the exercises at the bottom of chapter 9 of clojure for the brave and true (in particular the last one of searching multiple engines and returning the first hit of each) I mocked the actual search with slurp part to be this: (defn…
Palace Chan
  • 8,845
  • 11
  • 41
  • 93
0
votes
0 answers

Usage of LazyMapSequence when an array of Strings is excepted

I have a User object @objc(User) public class User: NSManagedObject { @NSManaged public var firstname: String @NSManaged public var lastname: String @NSManaged public var country: String @NSManaged public var friends: NSSet // of…
iOSGeek
  • 5,115
  • 9
  • 46
  • 74
0
votes
2 answers

How can you feed an iterable to multiple consumers in constant space?

How can you feed an iterable to multiple consumers in constant space? TLDR Write an implementation which passes the following test in CONSTANT SPACE, while treating min, max and sum as black boxes. def testit(implementation, N): assert…
jacg
  • 2,040
  • 1
  • 14
  • 27