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
2 answers

Converting thunk to sequence upon iteration

I have a server API that returns a list of things, and does so in chunks of, let's say, 25 items at a time. With every response, we get a list of items, and a "token" that we can use for the following server call to return the next 25, and so…
rix0rrr
  • 9,856
  • 5
  • 45
  • 48
0
votes
1 answer

Lazy stream does not work

I'm using Stream to create a lazy sequence. My sequence is combined from others sequences by ++. But my code does not work. Why? def select[T1, T2](s: Stream[T1], map: T1=>T2): Stream[T2] = { for (sv <- s) yield map(sv) } var innerCounter =…
Chronos
  • 1
  • 1
0
votes
1 answer

Clojure: why is sniptest producing LazySeq

I'm creating a template in enlive and having trouble with this snippet which produces lazyseq. When I try this sniptest in REPL it produces "clojure.lang.LazySeq@ba6da9f2". (h/sniptest (template-div) [:div.Row] (h/content (map…
Vesna
  • 345
  • 2
  • 11
0
votes
2 answers

How lazy sequence run in this code

Code is here: (def fib-seq (lazy-cat [0 1] (map + (rest fib-seq) fib-seq ))) As I could understand that the fib-seq is a lazy sequence generator that generate a serial of fibonacci number. By take a look at (take 5 fib-seq) I will get fibonacci…
Rugal
  • 2,612
  • 1
  • 15
  • 16
0
votes
2 answers

Oscilating function in Clojure

I can't solve this problem from the 4clojure site and the errors are not helping much: ;;Write an oscillating iterate: a function that takes an initial value and a ;;variable number of functions. It should return a lazy sequence of the…
loki
  • 2,271
  • 5
  • 32
  • 46
0
votes
1 answer

Executing a lazy sequence of functions

I'm wondering how to force a lazy sequence of functions to be evaluated. For example if I have a function that returns the integer 1: test.core=> (fn [] 1) # test.core=> ((fn []…
Allyl Isocyanate
  • 13,306
  • 17
  • 79
  • 130
0
votes
2 answers

clojure lazy function - Clojure Koan

"Iteration provides an infinite lazy sequence" (= (range 20) (take 20 (iterate inc 0))) So my question is why it start from 0 instead of 1 ? How to understand the laziness here ?
CodeFarmer
  • 2,644
  • 1
  • 23
  • 32
0
votes
1 answer

Implementation of lazy filter in clojure

On http://clojure.org/lazy, filter is defined this way: (defn filter "Returns a lazy sequence of the items in coll for which (pred item) returns true. pred must be free of side-effects." [pred coll] (let [step (fn [p c] …
tempestadept
  • 835
  • 4
  • 15
0
votes
1 answer

Clojure: Using a stream without holding head. Is this correct?

I want to put a lazy sequence somewhere to provide data as needed. I know I have to avoid keeping hold of the head of the sequence. I came up with the follwoing solution, did I miss something? (defn headless [s] (let [a (atom s)] (fn …
Falko
  • 1,028
  • 1
  • 12
  • 24
0
votes
1 answer

node.js : reading lines from csv into an array

I want to read some lines from a large csv file. A quick search here on SO pointed me to the 'lazy' module. Here's my attempt: items = [] stream = fs.createReadStream src lazy(stream) .lines .skip(1) .take(5) .forEach((line)-> …
tldr
  • 11,924
  • 15
  • 75
  • 120
0
votes
5 answers

Clojure 2d list to hash-map

I have an infinite list like that: ((1 1)(3 9)(5 17)...) I would like to make a hash map out of it: {:1 1 :3 9 :5 17 ...) Basically 1st element of the 'inner' list would be a keyword, while second element a value. I am not sure if it would not be…
Daniel Gruszczyk
  • 5,379
  • 8
  • 47
  • 86
0
votes
1 answer

"application: not a procedure" while generating prime numbers

I am trying to output the first 100 prime numbers and keep getting the error: application: not a procedure; expected a procedure that can be applied to arguments given: (#) arguments...: [none] The error is shown in my take$ procedure here: (if…
0
votes
2 answers

Is there a Python library for handling complicated mathematical sets (constructed using mathematical set-builder notation)?

I often work with multidimensional arrays whose array indices are generated from a complicated user-specified set. I'm looking for a library with classes for representing complicated sets with an arbitrary number of indices, and arbitrarily…
Gilead
  • 1,263
  • 10
  • 21
0
votes
1 answer

Sudden slowdown with lazy sequence

I had this code: :history (cons [t (:latest thing)] (take n (:history thing)) ) which was for adding a rolling window of recent history to a map on each iteration of my program. What I found was that after a certain number of iterations (~50) my…
Hendekagon
  • 4,565
  • 2
  • 28
  • 43
-1
votes
1 answer

Convert an infinite tree into an infinite stream

Description of the problem I have a lazy infinite binary tree: type 'a tree_node = TN of 'a * 'a inf_btree * 'a inf_btree and 'a inf_btree = 'a tree_node Lazy.t let rec ibt_map (f : 'a -> 'b) (t : 'a inf_btree) : 'b inf_btree = let TN (x,…
Addem
  • 3,635
  • 3
  • 35
  • 58
1 2 3
18
19