{"id":13458758,"url":"https://github.com/poetix/protonpack","last_synced_at":"2025-03-24T15:32:01.187Z","repository":{"id":19805534,"uuid":"23065617","full_name":"poetix/protonpack","owner":"poetix","description":"Stream utilities for Java 8","archived":false,"fork":false,"pushed_at":"2024-05-09T20:21:28.000Z","size":249,"stargazers_count":479,"open_issues_count":4,"forks_count":55,"subscribers_count":25,"default_branch":"master","last_synced_at":"2024-10-29T03:33:27.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/poetix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-08-18T09:27:50.000Z","updated_at":"2024-07-31T14:59:42.000Z","dependencies_parsed_at":"2024-01-03T01:20:48.733Z","dependency_job_id":"1cbb8bcc-e3f1-4136-8bf1-557d28de165e","html_url":"https://github.com/poetix/protonpack","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poetix%2Fprotonpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poetix%2Fprotonpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poetix%2Fprotonpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/poetix%2Fprotonpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/poetix","download_url":"https://codeload.github.com/poetix/protonpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245298193,"owners_count":20592562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T09:00:56.880Z","updated_at":"2025-03-24T15:31:56.166Z","avatar_url":"https://github.com/poetix.png","language":"Java","funding_links":[],"categories":["Java","Projects","项目","Functional libraries"],"sub_categories":["Functional Programming","函数式编程"],"readme":"protonpack\n==========\n\n[![Maven Central](https://img.shields.io/maven-central/v/com.codepoetics/protonpack.svg)](http://search.maven.org/#search%7Cga%7C1%7Cprotonpack)\n[![Build Status](https://travis-ci.org/poetix/protonpack.svg?branch=master)](https://travis-ci.org/poetix/protonpack)\n\nA small collection of ```Stream``` utilities for Java 8. Protonpack provides the following:\n\n* ```takeWhile``` and ```takeUntil```\n* ```skipWhile``` and ```skipUntil```\n* ```zip``` and ```zipWithIndex```\n* ```unfold```\n* ```MapStream```\n* ```aggregate```\n* ```Streamable\u003cT\u003e```\n* ```unique``` collector\n\nFor full API documentation, see (http://poetix.github.io/protonpack).\n\nAvailable from Maven Central:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.codepoetics\u003c/groupId\u003e\n    \u003cartifactId\u003eprotonpack\u003c/artifactId\u003e\n    \u003cversion\u003e1.16\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## takeWhile\n\nTakes elements from the stream while the supplied condition is met. ```takeUntil``` does the same, but with the condition negated.\n\n```java\nStream\u003cInteger\u003e infiniteInts = Stream.iterate(0, i -\u003e i + 1);\nStream\u003cInteger\u003e finiteInts = StreamUtils.takeWhile(infiniteInts, i -\u003e i \u003c 10);\n\nassertThat(finiteInts.collect(Collectors.toList()),\n           hasSize(10));\n```\n\n## skipWhile\n\nSkips elements from the stream while the supplied condition is met. ```skipUntil``` does the same, but with the condition negated.\n\n```java\nStream\u003cInteger\u003e ints = Stream.of(1,2,3,4,5,6,7,8,9,10);\nStream\u003cInteger\u003e skipped = StreamUtils.skipWhile(ints, i -\u003e i \u003c 4);\n\nList\u003cInteger\u003e collected = skipped.collect(Collectors.toList());\n\nassertThat(collected,\n           contains(4, 5, 6, 7, 8, 9, 10));\n```\n\n## zip\n\nCombines two streams using the supplied combiner function.\n\n```java\nStream\u003cString\u003e streamA = Stream.of(\"A\", \"B\", \"C\");\nStream\u003cString\u003e streamB  = Stream.of(\"Apple\", \"Banana\", \"Carrot\", \"Doughnut\");\n\nList\u003cString\u003e zipped = StreamUtils.zip(streamA,\n                                      streamB,\n                                      (a, b) -\u003e a + \" is for \" + b)\n                                 .collect(Collectors.toList());\n\nassertThat(zipped,\n           contains(\"A is for Apple\", \"B is for Banana\", \"C is for Carrot\"));\n```\n\n## unfold\n\nGenerates a (potentially infinite) stream using a generator that can indicate the end of the stream at any time by returning Optional.empty().\n\n```java\nStream\u003cInteger\u003e unfolded = StreamUtils.unfold(1, i -\u003e\n    (i \u003c 10)\n        ? Optional.of(i + 1)\n        : Optional.empty());\n\nassertThat(unfolded.collect(Collectors.toList()),\n           contains(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));\n```\n\n## stream\n\nTransforms a source type into a stream\n\n`stream(Optional\u003cT\u003e optional):`\n```java\nStream\u003cItem\u003e items = idStream.flatMap(id -\u003e StreamUtils.stream(fetchItem(id));\n```\n\n## Streamable\u003cT\u003e\n\nStreamable is to Stream as Iterable is to Iterator. Useful when you will want to stream repeatedly over some source.\n\n## unique\n\nA collector that returns the one and only item in a stream, if present, or throws an exception if multiple items are found.\n\n```java\nassertThat(Stream.of(1, 2, 3).filter(i -\u003e i \u003e 3).collect(CollectorUtils.unique()),\n           equalTo(Optional.empty()));\n\nassertThat(Stream.of(1, 2, 3).filter(i -\u003e i \u003e 2).collect(CollectorUtils.unique()),\n           equalTo(Optional.of(3)));\n\n// Throws NonUniqueValueException\nStream.of(1, 2, 3).filter(i -\u003e i \u003e 1).collect(CollectorUtils.unique());\n```\n\n## toFutureList\n\nA collector that converts a stream of `CompletableFuture\u003cT\u003e` into a `CompletableFuture\u003cList\u003cT\u003e\u003e`, which completes\nexceptionally if (and as soon as) any of the futures in the list completes exceptionally.\n\n```java\nFunction\u003cInteger, CompletableFuture\u003cInteger\u003e\u003e processAsynchronously = i -\u003e CompletableFuture.completedFuture(i * 2);\nassertThat(\n        Stream.of(1, 2, 3).map(processAsynchronously)\n                .collect(CompletableFutures.toFutureList())\n                .get(),\n        contains(2, 4, 6));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoetix%2Fprotonpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoetix%2Fprotonpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoetix%2Fprotonpack/lists"}