{"id":18687918,"url":"https://github.com/tenmax/pushable-stream","last_synced_at":"2025-04-12T05:30:55.934Z","repository":{"id":134627531,"uuid":"54656055","full_name":"tenmax/pushable-stream","owner":"tenmax","description":"A push-based java stream/reactive library","archived":false,"fork":false,"pushed_at":"2016-03-24T16:15:59.000Z","size":56,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-26T00:51:22.003Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tenmax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2016-03-24T16:13:03.000Z","updated_at":"2018-07-21T16:22:43.000Z","dependencies_parsed_at":"2023-08-15T19:51:58.878Z","dependency_job_id":null,"html_url":"https://github.com/tenmax/pushable-stream","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenmax%2Fpushable-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenmax%2Fpushable-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenmax%2Fpushable-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tenmax%2Fpushable-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tenmax","download_url":"https://codeload.github.com/tenmax/pushable-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248523576,"owners_count":21118528,"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-11-07T10:34:54.600Z","updated_at":"2025-04-12T05:30:55.890Z","avatar_url":"https://github.com/tenmax.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nJava Stream is a great reactive library. However, it is a pull-only reactive library. In some scenario, it is desirable to behave as \"push\" mode. This library implement the push-version of java stream library.\n\n# Usage\nI will put the library to JCenter repo sooooooon....\n\n# Examples\n\n## Mapper\nA mapper allows you to transform input to another format. Similar to [java.util.Stream#map](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#map-java.util.function.Function-)\n\n``` java\nPushableStream\u003cInteger, ?\u003e stream = PushableStream\n    .\u003cInteger\u003eof()\n    .map(i -\u003e i*2)\n    .map(i -\u003e \"test-\" + i)\n    .forEach(System.out::println);\n    \nstream.push(1);\nstream.push(2);\nstream.push(3,4,5);\n```\n        \nResult:\n\n```\ntest-2\ntest-4\ntest-6\ntest-8\ntest-10\n```        \n\n## Filter\n\nA filter allows you keep the matched item. Similar to [java.util.Stream#filter](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#filter-java.util.function.Predicate-)\n\n``` java\nPushableStream\u003cInteger, ?\u003e stream = PushableStream\n        .\u003cInteger\u003eof()\n        .filter(i -\u003e i % 2 == 0)\n        .forEach(System.out::println);\n\nstream.push(1,2,3,4,5);\n```\n\nResult:\n\n```\n2\n4\n```        \n\n## Collector\n\nA collector allows you reduce the items to a compact result. Similar to [java.util.Stream#collect](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#collect-java.util.stream.Collector-)\n\n\n``` java\nCollectResult\u003cLong\u003e result = CollectResult.create();\nPushableStream\u003cInteger, ?\u003e stream = PushableStream\n        .\u003cInteger\u003eof()\n        .collect(Collectors.counting(), result);\n\nstream.push(1,2,3,4,5);\nSystem.out.println(result.snapshot());\n```\n\nResult:\n```\n15\n```        \n\n\n## Multiple Collector\nIn java stream library, there could be only one collector result. But in pushable stream. We can have multiple collectors in one stream.\n\n```\nCollectResult\u003cLong\u003e count = CollectResult.create();\nCollectResult\u003cInteger\u003e sum = CollectResult.create();\nPushableStream\u003cInteger, ?\u003e stream = PushableStream\n        .\u003cInteger\u003eof()\n        .collect(counting(), count)\n        .collect(summingInt(i -\u003e i.intValue()), sum);\n\nstream.push(1,2,3,4,5);\nSystem.out.println(count.snapshot());\nSystem.out.println(sum.snapshot());\n```\n\nResult:\n```\n5\n15\n```\n\n## Multi-Threaded Collector\n\nJust like java stream. We support parallel execution to gain better performan\n\n``` java\nCollectResult\u003cLong\u003e count = CollectResult.create();\nPushableStream\u003cInteger, ?\u003e stream = PushableStream\n        .\u003cInteger\u003eof()\n//        .forEach((i) -\u003e System.out.println(Thread.currentThread().getName()))\n        .collect(counting(), count);\n\nstream.push(IntStream.rangeClosed(1, 1_000_000).boxed().parallel());\n\nSystem.out.println(count.snapshot());\n```\nResult:\n```\n1000000\n```\n\n## Fork the stream!\nSometimes, in the ETL path, the cost of pulling or transforming data may be expensive. Pushable stream allows you to reuse the stream for multiple purposes. For example, you can print the result to the console, save the result to file, and aggregate the data at the same time!\n\n``` java\nIntStream\n.range(0, 5)\n.boxed()\n.peek(PushableStream\n    .\u003cInteger\u003eof()\n    .forEach(System.out::println))\n.peek(PushableStream\n    .\u003cInteger\u003eof().map(i-\u003ei*2)\n    .forEach(System.out::println))\n.map(i -\u003e i * 3)\n.forEach(System.out::println);\n```\n\nResult:\n\n```\n0\n0\n0\n1\n2\n3\n2\n4\n6\n3\n6\n9\n4\n8\n12\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenmax%2Fpushable-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftenmax%2Fpushable-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftenmax%2Fpushable-stream/lists"}