protonpack

Stream Utilities for Java 8

Лицензия

Лицензия

MIT
Категории

Категории

protonpack Универсальные библиотеки Functional Programming
Группа

Группа

com.codepoetics
Идентификатор

Идентификатор

protonpack
Последняя версия

Последняя версия

1.16
Дата

Дата

Тип

Тип

jar
Описание

Описание

protonpack
Stream Utilities for Java 8
Ссылка на сайт

Ссылка на сайт

https://github.com/poetix/protonpack
Система контроля версий

Система контроля версий

http://github.com/poetix/protonpack

Скачать protonpack

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.codepoetics/protonpack/ -->
<dependency>
    <groupId>com.codepoetics</groupId>
    <artifactId>protonpack</artifactId>
    <version>1.16</version>
</dependency>
// https://jarcasting.com/artifacts/com.codepoetics/protonpack/
implementation 'com.codepoetics:protonpack:1.16'
// https://jarcasting.com/artifacts/com.codepoetics/protonpack/
implementation ("com.codepoetics:protonpack:1.16")
'com.codepoetics:protonpack:jar:1.16'
<dependency org="com.codepoetics" name="protonpack" rev="1.16">
  <artifact name="protonpack" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.codepoetics', module='protonpack', version='1.16')
)
libraryDependencies += "com.codepoetics" % "protonpack" % "1.16"
[com.codepoetics/protonpack "1.16"]

Зависимости

test (2)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.13
org.hamcrest : hamcrest jar 2.2

Модули Проекта

Данный проект не имеет модулей.

protonpack

Maven Central Build Status

A small collection of Stream utilities for Java 8. Protonpack provides the following:

  • takeWhile and takeUntil
  • skipWhile and skipUntil
  • zip and zipWithIndex
  • unfold
  • MapStream
  • aggregate
  • Streamable<T>
  • unique collector

For full API documentation, see (http://poetix.github.io/protonpack).

Available from Maven Central:

<dependency>
    <groupId>com.codepoetics</groupId>
    <artifactId>protonpack</artifactId>
    <version>1.16</version>
</dependency>

takeWhile

Takes elements from the stream while the supplied condition is met. takeUntil does the same, but with the condition negated.

Stream<Integer> infiniteInts = Stream.iterate(0, i -> i + 1);
Stream<Integer> finiteInts = StreamUtils.takeWhile(infiniteInts, i -> i < 10);

assertThat(finiteInts.collect(Collectors.toList()),
           hasSize(10));

skipWhile

Skips elements from the stream while the supplied condition is met. skipUntil does the same, but with the condition negated.

Stream<Integer> ints = Stream.of(1,2,3,4,5,6,7,8,9,10);
Stream<Integer> skipped = StreamUtils.skipWhile(ints, i -> i < 4);

List<Integer> collected = skipped.collect(Collectors.toList());

assertThat(collected,
           contains(4, 5, 6, 7, 8, 9, 10));

zip

Combines two streams using the supplied combiner function.

Stream<String> streamA = Stream.of("A", "B", "C");
Stream<String> streamB  = Stream.of("Apple", "Banana", "Carrot", "Doughnut");

List<String> zipped = StreamUtils.zip(streamA,
                                      streamB,
                                      (a, b) -> a + " is for " + b)
                                 .collect(Collectors.toList());

assertThat(zipped,
           contains("A is for Apple", "B is for Banana", "C is for Carrot"));

unfold

Generates a (potentially infinite) stream using a generator that can indicate the end of the stream at any time by returning Optional.empty().

Stream<Integer> unfolded = StreamUtils.unfold(1, i ->
    (i < 10)
        ? Optional.of(i + 1)
        : Optional.empty());

assertThat(unfolded.collect(Collectors.toList()),
           contains(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));

stream

Transforms a source type into a stream

stream(Optional<T> optional):

Stream<Item> items = idStream.flatMap(id -> StreamUtils.stream(fetchItem(id));

Streamable

Streamable is to Stream as Iterable is to Iterator. Useful when you will want to stream repeatedly over some source.

unique

A collector that returns the one and only item in a stream, if present, or throws an exception if multiple items are found.

assertThat(Stream.of(1, 2, 3).filter(i -> i > 3).collect(CollectorUtils.unique()),
           equalTo(Optional.empty()));

assertThat(Stream.of(1, 2, 3).filter(i -> i > 2).collect(CollectorUtils.unique()),
           equalTo(Optional.of(3)));

// Throws NonUniqueValueException
Stream.of(1, 2, 3).filter(i -> i > 1).collect(CollectorUtils.unique());

toFutureList

A collector that converts a stream of CompletableFuture<T> into a CompletableFuture<List<T>>, which completes exceptionally if (and as soon as) any of the futures in the list completes exceptionally.

Function<Integer, CompletableFuture<Integer>> processAsynchronously = i -> CompletableFuture.completedFuture(i * 2);
assertThat(
        Stream.of(1, 2, 3).map(processAsynchronously)
                .collect(CompletableFutures.toFutureList())
                .get(),
        contains(2, 4, 6));

Версии библиотеки

Версия
1.16
1.15
1.14
1.13
1.11
1.10
1.9
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1.0
thecolourofmagic