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

Processing SQL Queries as Lazy Streams in Racket

Language: Racket (with SQL query code/pointer) Libraries: db, racket/stream, racket/sequence Goal: lazily process the value of sql queries using streams in Racket. Question 1: how do you manipulate SQL query stream objects in Racket? (I can get the…
Triage
  • 21
  • 1
  • 3
1
vote
1 answer

Do Kotlin Sequences cache intermediate results?

When operating Kotlin sequences with functional APIs such as map, flatMap, +, etc., are computed intermediate results cached so upon second evaluation there is no recomputation? If not, replacing Lists with Sequences could in some situations cause…
Shreck Ye
  • 1,591
  • 2
  • 16
  • 32
1
vote
1 answer

Writing a lazy-as-possible unfoldr-like function to generate arbitrary factorizations

problem formulation Informally speaking, I want to write a function which, taking as input a function that generates binary factorizations and an element (usually neutral), creates an arbitrary length factorization generator. To be more specific,…
peter pun
  • 384
  • 1
  • 8
1
vote
0 answers

swift lazy sequences - why does compiler complain when definition introduced

I'm working with Lazy Sequences of Ints: let a = [1,2,3].lazy I start by defining a Stream of Ints like this: protocol Stream: LazySequenceProtocol where Element == Int {} extension LazySequence: Stream where Element == Int {} extension…
Cortado-J
  • 2,035
  • 2
  • 20
  • 32
1
vote
0 answers

Java/Clojure interop can't realize lazy sequence in Java

I am passing a map generated in Clojure into Java ultimately destined for a JTable. The use of the map function creates a lazy sequence that even with doall, into {} is not realized. Clojure: (defn test-lz-seq [] (let [myvec [[1 2 nil][3 4 nil][…
1
vote
1 answer

Why does my lazy filtered list in scheme consume so much memory?

I'm currently learning to use some slightly more advanced features of scheme, and I've hit a road-block with lazy lists. Basically, I'm trying to create an infinite, lazily generated list, and apply a lazy filter on it, and only take a single…
1
vote
1 answer

How to mental model this clojure fibonacci generator?

Came across this interesting implementation of Fibonacci generator in clojure. Bit difficult to understand the self-reference part. Any help on mental modelling this would be very useful. (def fib-seq (lazy-cat [0 1] (map + (rest fib-seq)…
Kannan Ramamoorthy
  • 3,980
  • 9
  • 45
  • 63
1
vote
3 answers

Why is this recursive map function only being applied to the last two elements in the list?

This is the problem given: What are the first 8 elements in the following list? mystery = 0 : 10 : (map(+1)mystery) The answer is [0,10,1,11,2,12,3,13...] But in my opinion the answer should be [0,10,1,11,1,11,2,12]. The following steps show…
1
vote
1 answer

Swift Problem with Composing Lazy Sequence Transforms

I'm continuing my foray into functional swift and very much enjoying the challenge. I'm working with Transforms which turn elements into lazy sequences. To state the error up front, I'm getting: Cannot convert value of type 'Transform' (aka '(Int)…
Cortado-J
  • 2,035
  • 2
  • 20
  • 32
1
vote
0 answers

Testing laziness of IsString s => s -> Bool function

Is there any way I can test that a function p :: IsString s => s -> Bool evaluates its input lazily? That is, it only consumes a part of its input when determining its result. And is it possible in such a way that it's compatible with both String…
sshine
  • 15,635
  • 1
  • 41
  • 66
1
vote
1 answer

Monadic folding of Data.Text

I would like to write a function countDigits :: Text -> Either Text (Map Int Int) that builds a histogram of digit characters and fails if there are non-digit characters with a message that indicates the first or all non-digit characters. If this…
sshine
  • 15,635
  • 1
  • 41
  • 66
1
vote
2 answers

Does C++17 offer generators or another built-in way to transform a non-instantiated sequence in parallel?

I'm trying to transform a sequence of numbers in parallel in C++17 and store the results in a vector. But so far I'm unable to find a way to represent the sequence without explicitly filling an array with it, like so: void transformRange(size_t…
All The Rage
  • 743
  • 5
  • 24
1
vote
0 answers

Slowness in LAZY Enumeration

ic = new ImapClient("imap.yandex.com", Email, email.Password, AuthMethods.Login, 993, true); var mailMessage = ic.SearchMessages(SearchCondition.From("somemail@gmail.com"), false, true).ToList(); if (mailMessage.Count > 0) { foreach…
Ayan_84
  • 645
  • 1
  • 6
  • 18
1
vote
1 answer

How does lazy-seq accumulate the result?

Here is the implementation of partition function in clojurescript. The other methods are removed for simplicity. I have hard time understanding how the lazy-seq accumulates the result. At the end there is a when which if I understand correctly will…
Sam R.
  • 16,027
  • 12
  • 69
  • 122
1
vote
2 answers

Create java stream with supplier lazyly

it is possible, with Java 8 stream API, to create Stream that is not evaluated until is necessary? I mean. I have a stream that processes a list of elements, in one of the middle operations (map) I have to read go through another stream and I want…
colymore
  • 11,776
  • 13
  • 48
  • 90