Skip to main content

All Questions

Tagged with
1 vote
0 answers
50 views

Lazy de-serialization of a JSON array as a Stream<T> [duplicate]

Consider I have a large (potentially infinite) array of JSON objects: [ { "id": 41, "name": "foo" }, { "id": 42, &...
Bass's user avatar
  • 5,368
3 votes
1 answer
68 views

Java Stream API - Lazy Evaluation [duplicate]

This code does not print anything: List.of("a","b","c","D").stream() .map(m -> { System.out.println(m); return m; }) .count(); ...
Noel's user avatar
  • 10.5k
0 votes
1 answer
81 views

why are the results of the 2 streams different? [duplicate]

The Stream API supports lazy operations, so I understand that it calculates vertically. However, the results are different depending on the location of the limit method. Why does the operation ...
shining's user avatar
0 votes
1 answer
860 views

How do I avoid using try-with-resources or close() in this example?

I am trying to stream data from the internet using java.util.stream.Stream. I have an implementation that works. Here is it below. final URL url = new URI ( "INSERT YOUR ...
davidalayachew's user avatar
1 vote
0 answers
54 views

How to transfere Kotlin fragment code "by lazy " to Java fragment?

I have kotlin working fragment. I want to rewrite it to Java. I need to get viewModell inisialization in Java. How do i get it? I tried to use bitecode migration, but it gives a long code. Kotlin file:...
Павел К's user avatar
1 vote
0 answers
63 views

How to create a CompletableFuture that does not compute until CompletableFuture::get is called? [duplicate]

The title is mostly self-explanatory. I am trying to solve a question, but in order to do so, I need the CompletableFuture to NOT attempt execution until someone starts running it via ...
davidalayachew's user avatar
0 votes
2 answers
426 views

Java streams and lazy collections

I have a method which returns a Collection of objects by performing some costly operation (e.g. using a database for resolving objects by ther ID). Let's use this method as an example: public static ...
Ricky Sixx's user avatar
-1 votes
1 answer
203 views

Issue with Java IntStream whilst trying to solve a codewars problem (Prime Streaming PG-13) [duplicate]

I signed up on codewars in March and I have finished a number of challenges. I am encountering difficulty with the following. The name is Prime Streaming (PG-13) and is highlighted below. Create an ...
Hector Williams's user avatar
-3 votes
1 answer
67 views

Lazy Evaluation - Java [duplicate]

Can somebody make an detailed explanation (and i mean really detailed, im dumb) of lazy evaluation in java and maybe also explain what is meant with eager evaluation? Why is this bringing a runtime-...
LinkMuffin's user avatar
3 votes
1 answer
125 views

Weird streams behavior with sorted() and concat()

Stream evaluation is usually lazy (by default), unless statefull operations exist as part of the pipeline. I encountered a case where the lazyness is violated due to stateful operation and I don't ...
aviad cohen's user avatar
3 votes
2 answers
119 views

Lazily calls a method in a java Stream

I have an expensive method that I only want to call it when necessary in a stream. Here is an example: public static Optional<MyObject> findTarget(String input, List<MyObject> myList) { ...
user1589188's user avatar
  • 5,738
0 votes
1 answer
312 views

How to generate lazy stream from a fixed number of expressions in Java?

I would like to get the same as Stream.of, but lazy. I.e. I want to do the same as Stream<MyClass> s = Stream.of( expression1(), expression2(), expression3(), ... ) I can do List<...
Dims's user avatar
  • 51.4k
0 votes
2 answers
137 views

Evaluation strategy in Java

I'm used to believing that functions in Java are always applicatively evaluated, that is, all the function arguments are evaluated before being applied to the function; until today when I was playing ...
Futarimiti's user avatar
1 vote
1 answer
94 views

Java - would this method call ever be evaluated?

My IDE is marking the following code snippet's second function call as a potential source for a NullPointerException, and I'm unsure if that is actually the case. The snippet: Sprite tmp = ...
devor110's user avatar
  • 141
3 votes
1 answer
943 views

Are java streams able to lazilly reduce from map/filter conditions?

I am using a functional programming style to solve the Leetcode easy question, Count the Number of Consistent Strings. The premise of this question is simple: count the amount of values for which the ...
AaronC's user avatar
  • 743

15 30 50 per page
1
2 3 4 5
8