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
1
vote
1 answer

ArgumentError - tried to call lazy take_while without a block

Imagine, that there are M large text files each with N lines, that are indexed from 1 to M*N. My goal is to get either all lines after the index X or just last 10 of them if X isn't provided. I could do an external if to split these two formulas,…
Nakilon
  • 34,866
  • 14
  • 107
  • 142
1
vote
1 answer

Clojure lazy-seq gives me ArithmeticException

I am trying to re-implement my custom map function, but it works in a strange way. Could some one explain why it happens? (defn my-map [f coll] (lazy-seq (when-let [s (seq coll)] (cons (f (first s)) (my-map f (rest s)))))) (take 10…
1
vote
2 answers

What will the behaviour of line-seq be?

I'd like to understand the behaviour of a lazy sequence if I iterate over with doseq but hold onto part of the first element. (with-open [log-file-reader (clojure.java.io/reader (clojure.java.io/file input-file-path))] ; Parse line parse-line…
Joe
  • 46,419
  • 33
  • 155
  • 245
1
vote
5 answers

Partitioning across partitions in Clojure?

Here are some values. Each is a sequence of ascending (or otherwise grouped) values. (def input-vals [[[1 :a] [1 :b] [2 :c] [3 :d] [3 :e]] [[1 :f] [2 :g] [2 :h] [2 :i] [3 :j] [3 :k]] [[1 :l] [3 :m]]]) I can partition them each…
Joe
  • 46,419
  • 33
  • 155
  • 245
1
vote
1 answer

Clojure modify LazySeq

I inherited some Java code that does the following: 1) it receives from Clojure a LazySeq object (which is made up of a number of PersistentHashMap objects) 2) it then passes this same LazySeq object (unchanged) back to a Clojure script where it is…
Chris
  • 11
  • 1
1
vote
2 answers

clojure: create a lazy-seq containing another lazy-seq

I would like to create a lazy-seq containing another lazy-seq using clojure. The data structure that I aready have is a lazy-seq of map and it looks like this: ({:a 1 :b 1}) Now I would like to put that lazy-seq into another one so that the result…
Horace
  • 1,198
  • 2
  • 17
  • 31
1
vote
2 answers

clojure: howto build a string from two sequences?

I struggling with a problem for hours now... I want to build a link with values from two sequences. (doseq [item photoset-name] (prn item )) (doseq [item-name photoset-id] (prn item-name )) output:…
Nico
  • 1,071
  • 1
  • 23
  • 39
1
vote
2 answers

clojure: how to get values from lazy seq?

Iam new to clojure and need some help to get a value out of a lazy sequence. You can have a look at my full data structure here: http://pastebin.com/ynLJaLaP What I need is the content of the title: {: _content AlbumTitel2} I managed to get a list…
Nico
  • 1,071
  • 1
  • 23
  • 39
1
vote
3 answers

Clojure lazy-sequence where sequence grows from both ends

I have written a function (listed below) which returns a function that returns n items from an infiniate set as defined in the comments. ; Returns a function which in turn returns a vector of 'n' items, with init-val being the 'middle' value, ;…
satch5150
  • 51
  • 1
1
vote
2 answers

Lazy list s-expression matrix in smalltalk

So I have a class to create in smalltalk called LazyMatrix. The class only has 1 instance variable and cannot be a subclass of anything but Object. The instance variable of LazyMatrix is called block and must be a back. I initialize LazyMatrix like…
Wes Field
  • 3,291
  • 6
  • 23
  • 26
1
vote
1 answer

Recursion in a stream

I have the code (define (add-ten s) (let ([f (lambda(s) ((cons 10 (car (s))) (cdr (s))))]) (f s))) s could be a stream like powers (define powers (letrec ([f (lambda (x) (cons x (lambda () (f (* x 2)))))]) (lambda () (f 2)))) My…
Rea
  • 67
  • 5
1
vote
1 answer

Combining LazySeqs into one collection of maps

I'm trying to combine a couple of LazySeqs into one collection of maps. ("a" "b" "c" ...) ("x" "y" "z" ...) into ({:key1 "a" :key2 "x"} {:key1 "b" :key2 "y"} ...) It is guaranteed that the LazySeqs are of the same length. What would be the…
fuji
  • 1,173
  • 1
  • 10
  • 27
0
votes
1 answer

Eager map in Python

In Python the map function is lazy, but most often I need an eager map. For example, trying to slice a map object results in an error: >>>> map(abs, [3, -1, -4, 1])[1:] Traceback (most recent call last): File "", line 1, in…
0
votes
1 answer

Returning lazy sequences

I have a lazy sequence I do some operations on and want to return from a function func getSeq() -> ??? { let a = array.lazy ./* ... operations like map, filter, etc */ } The final type of a…
Jomy
  • 514
  • 6
  • 22
0
votes
1 answer

Lazily Mapping an Array Using a Throwing Closure

When lazily mapping an array of values, I receive an instance of type LazyMapSequence as expected: Welcome to Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50). Type :help for assistance. 1> let numbers = Array(1...5) numbers:…
goofy4224
  • 141
  • 1
  • 8