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

Refactoring lazy functional code in Swift 5

I'm wanting to refactor some lazy functional swift. To explain the situation I'll explain the equivalent eager situation first: let numbers = 1...10 do { print("==================== EAGER INLINE =============================") /// We start with…
0
votes
2 answers

Pairwise Sequence Processing to compare db tables

Consider the following Use case: I want to iterate through 2 db tables in parallel and find differences and gaps/missing records in either table. Assume that 1) pk of table is an Int ID field; 2) the tables are read in ID order; 3) records may be…
BrendanC
  • 463
  • 1
  • 7
  • 18
0
votes
1 answer

Clojure: NullPointerException using LazySeq

I get a NullPointerException when trying to access LazySeq the first time, line-items - which takes some time to evaluate, then it breaks with NullPointerException on the next line calculating total-exc: (defn orders->invoice [db billing-account-id…
Sasha
  • 1,500
  • 4
  • 14
  • 25
0
votes
1 answer

How to define the partitions (factorizations w.r.t. concatenation) of a sequence as a lazy sequence of lazy sequences in Clojure

I am new to Clojure and I want to define a function pt taking as arguments a number n and a sequence s and returning all the partitions of s in n parts, i.e. its factorizations with respect to n-concatenation. for example (pt 3 [0 1 2]) should…
0
votes
2 answers

'Array' is not convertible to 'Array'

I can create an iterator to create prefixes: extension Array where Element == Int { func prefixesInt() -> AnyIterator<[Element]> { var length = 0 return AnyIterator { guard length < self.count else { return nil } length += 1 …
Cortado-J
  • 2,035
  • 2
  • 20
  • 32
0
votes
1 answer

Python nested lazy lists

I'm trying to plot a 2-D image with matplotlib, which expects data points in nested list format. I've got as far as a very neat, idiomatic way to generate this: zs = [[cost_at(x, y) for x in x_range] for y in y_range] plt.contourf(x_range, y_range,…
rwallace
  • 31,405
  • 40
  • 123
  • 242
0
votes
1 answer

Clojure / seeseaw.core/table lazy-seq retrieval failure

My "(list-projects)" method queries out a map from a SQLITE database. (doall (apply prn (pm.models.db/list-projects))) pm.core==>{:id 1, :name "MyTestProj", :owner "mbc", :date "2017-12-19 13:12:45"} {:id 2, :name "newproject1", :owner…
0
votes
1 answer

Why view method is deprecated from ParSeqLike at Scala?

I tried to combine an advantages of Lazy and Parallel Collections like that: Vector( /* some values....*/ ).par.view - it gives a huge performance boost.But Scala 2.12 marks the method as deprecated for ParSeqLike. What is wrong with a lazy usage…
0
votes
3 answers

What is meaning of NSMutableDictionary.lazy in swift?

I am confused about where to use lazy functionality, I mean to say in which type of condition I should use lazy keyword in the collection.
Brijesh Shiroya
  • 3,323
  • 1
  • 13
  • 20
0
votes
1 answer

Scala NullPointerException unless lazy

def fix[A, B](fn : Function2[Function1[A, B], A, B]) : Function1[A, B] = (x : A) => fn(fix(fn), x) lazy val fibs1 = fix[(Int, Int), Stream[Int]]( (fn, a) => a._1 #:: fn((a._2, a._1 + a._2)) ) val fibs2 = fix[(Int, Int),…
Carl
  • 13
  • 5
0
votes
1 answer

Python3, a lazy print

for my last project in Python3, i used a custom lazy generator to generate my data. Then use imap from a Pool (multiprocessing). So at this point, not any computation have been made. The next step is to output the computed data on a file. To do so,…
Paul
  • 315
  • 1
  • 9
0
votes
0 answers

Is there a lazy method of sequencing InputStream futures?

So I am cleaning up code in my code base, I have found one notable bottleneck. /** * Gets an InputStream to MP3Data for the returned information from a request * @param synthText List of Strings you want to be synthesized into MP3 data * @return…
Skylion
  • 2,696
  • 26
  • 50
0
votes
2 answers

Making a function lazy in clojure

I have this function which seems to work fine on limited collections, but not on infinite ones. Is there a way to construct a lazy-seq in it to get it run with infinite coll's, like: (take 3 (m inc (range))) => (1 2 3)? (defn m [f c] (reduce #(conj…
user4813927
0
votes
1 answer

Random numbers in linq queries

Is it true that random data inside a lazy statement might get evaluated differently at runtime? With the following code, I see "wow" printed to the console many times. However, if I force the result of the query (i.e. call ToList() on xs and ys),…
rookie
  • 2,783
  • 5
  • 29
  • 43
0
votes
2 answers

Is there a lazy version of F#'s Seq.groupBy function?

I would like to group a very large sequence lazily using code like the following: // native F# version let groups = Seq.initInfinite id |> Seq.groupBy (fun i -> i % 10) for (i, group) in groups |> Seq.take 5 do printfn "%A: %A" i…
Brian Berns
  • 15,499
  • 2
  • 30
  • 40