Class IterableStream<T>

java.lang.Object
com.azure.core.util.IterableStream<T>
Type Parameters:
T - The type of value in this Iterable.
All Implemented Interfaces:
Iterable<T>
Direct Known Subclasses:
AnalyzeHealthcareEntitiesResultCollection, AnalyzeSentimentResultCollection, CategorizedEntityCollection, ClassificationCategoryCollection, ContinuablePagedIterable, DetectLanguageResultCollection, ExtractKeyPhrasesResultCollection, ExtractSummaryResultCollection, KeyPhrasesCollection, LinkedEntityCollection, MultiCategoryClassifyResultCollection, PiiEntityCollection, RecognizeCustomEntitiesResultCollection, RecognizeEntitiesResultCollection, RecognizeLinkedEntitiesResultCollection, RecognizePiiEntitiesResultCollection, SingleCategoryClassifyResultCollection, SummarySentenceCollection

public class IterableStream<T> extends Object implements Iterable<T>
This class provides utility to iterate over values using standard 'for-each' style loops or to convert them into a Stream and operate in that fashion.

Code sample using Stream

 // process the stream
 myIterableStream.stream().forEach(resp -> {
     if (resp.getStatusCode() == HttpURLConnection.HTTP_OK) {
         System.out.printf("Response headers are %s. Url %s%n", resp.getDeserializedHeaders(),
             resp.getRequest().getUrl());
         resp.getElements().forEach(value -> System.out.printf("Response value is %d%n", value));
     }
 });
 

Code sample using Iterator

 // Iterate over iterator
 for (PagedResponseBase<String, Integer> resp : myIterableStream) {
     if (resp.getStatusCode() == HttpURLConnection.HTTP_OK) {
         System.out.printf("Response headers are %s. Url %s%n", resp.getDeserializedHeaders(),
             resp.getRequest().getUrl());
         resp.getElements().forEach(value -> System.out.printf("Response value is %d%n", value));
     }
 }
 

Code sample using Stream and filter

 // process the stream
 myIterableStream.stream().filter(resp -> resp.getStatusCode() == HttpURLConnection.HTTP_OK)
     .limit(10)
     .forEach(resp -> {
         System.out.printf("Response headers are %s. Url %s%n", resp.getDeserializedHeaders(),
             resp.getRequest().getUrl());
         resp.getElements().forEach(value -> System.out.printf("Response value is %d%n", value));
     });
 
See Also:
  • Constructor Details

    • IterableStream

      public IterableStream(Flux<T> flux)
      Creates an instance with the given Flux.
      Parameters:
      flux - Flux of items to iterate over.
      Throws:
      NullPointerException - If flux is null.
    • IterableStream

      public IterableStream(Iterable<T> iterable)
      Creates an instance with the given Iterable.
      Parameters:
      iterable - Collection of items to iterate over.
      Throws:
      NullPointerException - If iterable is null.
  • Method Details