{"id":31663881,"url":"https://github.com/smallibs/hpas","last_synced_at":"2025-10-07T20:16:20.376Z","repository":{"id":142087843,"uuid":"62540575","full_name":"Smallibs/hpas","owner":"Smallibs","description":"Functional ADT And Asynchronous stuff in Java ","archived":false,"fork":false,"pushed_at":"2025-09-05T11:49:36.000Z","size":456,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-05T13:32:01.807Z","etag":null,"topics":["asynchronous","functional-programming","monadic-interface"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Smallibs.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2016-07-04T07:25:26.000Z","updated_at":"2025-09-05T11:49:39.000Z","dependencies_parsed_at":"2025-07-31T06:29:18.477Z","dependency_job_id":"8020d669-5632-4374-98bc-5ff66bfd0a9b","html_url":"https://github.com/Smallibs/hpas","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Smallibs/hpas","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smallibs%2Fhpas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smallibs%2Fhpas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smallibs%2Fhpas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smallibs%2Fhpas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Smallibs","download_url":"https://codeload.github.com/Smallibs/hpas/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Smallibs%2Fhpas/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278838744,"owners_count":26054785,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["asynchronous","functional-programming","monadic-interface"],"created_at":"2025-10-07T20:16:18.232Z","updated_at":"2025-10-07T20:16:20.369Z","avatar_url":"https://github.com/Smallibs.png","language":"Java","readme":"# HiPeAS\n\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/052bbdb13acf4b35bd5bbb485f6cad25)](https://app.codacy.com/manual/d-plaindoux/hpas?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=d-plaindoux/hpas\u0026utm_campaign=Badge_Grade_Dashboard)\n[![Coverage Status](https://coveralls.io/repos/github/d-plaindoux/hpas/badge.svg?branch=master)](https://coveralls.io/github/d-plaindoux/hpas?branch=master)\n[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)\n[![Maven Central](https://img.shields.io/maven-central/v/org.smallibs/hpas.svg)](http://search.maven.org/#artifactdetails%7Corg.smallibs%7Chpas%7C0.5%7Cjar)\n\nFunctional paradigm deeply drives the design with a taste of OO for encapsulation and chaining methods which mimics infix\noperators like Haskell monad function `\u003e\u003e=`. \n\nIn addition, with version 21 of Java an Async/Await DSL like is available. \n\nSince such ADT provides traditional map, flapmap etc. functions for a DSL perspective are also given in order to increase the code readability.\n\n## A taste of HiPeAS\n\n```java\nExecutor executor = ExecutorHelper.create(Executors.newSingleThreadExecutor());\nPromise\u003cString\u003e helloWorldPromise = executor.async(() -\u003e \"Hello\").and(s -\u003e s + \" world!\");\n```\n\n## HiPeAS overview\n\n### Synchronous data types\n\nBasically well known `MayBe` and `Try` are available for this purpose. Theses ADT are also the basis for the asynchronous part\nof this library.\n\n### Asynchronous computational model\n\n### Executors\n\n```java\nExecutor executor = ExecutorHelper.create(Executors.newSingleThreadExecutor());\n```\n\n#### `async`\n\nIn Executor **\u0026lt;T\u0026gt; async :: (() -\u003e T) \u0026rarr; Promise\u0026lt;T\u0026gt;**\n\n```java\nPromise\u003cInteger\u003e integerPromise = executor.async(() -\u003e 1);\n```\n\n#### `await`\n\nIn ExecutorHelper **\u0026lt;T\u0026gt; await :: (Promise\u0026lt;T\u0026gt;, Duration) \u0026rarr; Try\u0026lt;T\u0026gt;**\n\n```java\nTry\u003cInteger\u003e result = ExecutorHelper.await(integerPromise, Duration.TWO_SECONDS);\n```\n\n### Promise\n\n#### `and` or `map` \n\nIn Promise\u0026lt;T\u0026gt; **\u0026lt;R\u0026gt; map :: (T \u0026rarr; R) \u0026rarr; Promise\u0026lt;R\u0026gt;**\n\nIn Promise\u0026lt;T\u0026gt; **\u0026lt;R\u0026gt; and :: (T \u0026rarr; R) \u0026rarr; Promise\u0026lt;R\u0026gt;**\n\n```java\nintegerPromise.map(i -\u003e i + 1);\nintegerPromise.and(i -\u003e i + 1);\n```\n\n#### `then` or `flatmap`\n\nIn Promise\u0026lt;T\u0026gt; **\u0026lt;R\u0026gt; flatmap :: (T \u0026rarr; Promise\u0026lt;R\u0026gt;) \u0026rarr; Promise\u0026lt;R\u0026gt;**\n\nIn Promise\u0026lt;T\u0026gt; **\u0026lt;R\u0026gt; then :: (T \u0026rarr; Promise\u0026lt;R\u0026gt;) \u0026rarr; Promise\u0026lt;R\u0026gt;**\n\n```java\nintegerPromise.flatmap(i -\u003e executor.async(() -\u003e i + 1));\nintegerPromise.then(i -\u003e executor.async(() -\u003e i + 1));\n```\n\n#### Back to the Future\n\nIn Promise\u0026lt;T\u0026gt; **getFuture :: () \u0026rarr; Future\u0026lt;T\u0026gt;**\n\n```java\nintegerPromise.getFuture();\n```\n \n### Conclude on success\n\nIn Promise\u0026lt;T\u0026gt; **onSuccess :: (T \u0026rarr; void) \u0026rarr; Promise\u0026lt;T\u0026gt;**\n\n```java\nintegerPromise.onSuccess(i -\u003e System.println(i))\n```\n\n### Conclude on failure\n\nIn Promise\u0026lt;T\u0026gt; **onFailure :: (Throwable \u0026rarr; void) \u0026rarr; Promise\u0026lt;T\u0026gt;**\n\n```java\nintegerPromise.onFailure(t -\u003e t.printStackTrace(System.err))\n```\n\n### Conclude on complete\n\nIn Promise\u0026lt;T\u0026gt; **onComplete :: (Try\u0026lt;T\u0026gt; \u0026rarr; void) \u0026rarr; Promise\u0026lt;T\u0026gt;**\n\n```java\nintegerPromise.onComplete(t -\u003e t.fold(integerPromise::onSuccess, integerPromise::onFailure));\n```\n\n## Async Await DSL\n\nNow we can use async/await mechanism using Loom virtual thread. We can now await for a promise implying an\nasynchronous mechanism based on thread parking if it's a virtual thread or a blocking procedure for system\nthread.\n\n```java\nvar executor = ExecutorHelper.create(Executors.newVirtualThreadPerTaskExecutor());\n\nvar aLongAddition = executor.async(() -\u003e {\n    var firstInteger = executor.async(() -\u003e /* do something */ 2);\n    Thread.sleep(3000); // Current thread do nothing during 3 seconds\n    var firstInteger = executor.async(() -\u003e /* do something else */ 5);\n\n    return firstInteger.await() + secondInteger.await(); // Await force virtual thread parking \n}).await(); // System thread waiting for the result\n```\n\n## Functor, Applicative and Monad\n\nIn addition monadic approach is available for each ADT. As usual `Monad` ihnerits `Applicative` which inherits `Functor`.\n\n### Functor\n\nIn PromiseHelper **functor\u0026lt;T\u0026gt; :: Promise\u0026lt;T\u0026gt; → Functor\u0026lt;T\u0026gt;**\n\n```java\nFunctor\u003cPromise, Integer, Promise\u003cInteger\u003e\u003e p1 = functor(executor.async(() -\u003e 1));\nHK\u003cPromise, Integer, Promise\u003cInteger\u003e\u003e p2 = p1.map(i -\u003e i + 1);\n```\n### Applicative\n\nIn PromiseHelper **applicative\u0026lt;T\u0026gt; :: Promise\u0026lt;T\u0026gt; → Applicative\u0026lt;T\u0026gt;**\n\n```java\nApplicative\u003cPromise, Integer, Promise\u003cInteger\u003e\u003e p1 = applicative(executor.async(() -\u003e 1));\nHK\u003cPromise, Integer, Promise\u003cInteger\u003e\u003e p2  = p1.apply(functor(executor.async(() -\u003e i -\u003e i + 1)));\n```\n### Monad\n\nIn PromiseHelper **monad\u0026lt;T\u0026gt; :: Promise\u0026lt;T\u0026gt; → Monad\u0026lt;T\u0026gt;**\n\n```java\nMonad\u003cPromise, Integer, Promise\u003cInteger\u003e\u003e p1 = monad(executor.async(() -\u003e 1));\nHK\u003cPromise, Integer, Promise\u003cInteger\u003e\u003e p2 = p1.flatmap(i -\u003e executor.async(() -\u003e i + 1));\n```\n\n## CompletableFuture and Promise\n\nIn CompletableFutureHelper **completableFuture\u0026lt;T\u0026gt; :: Promise\u0026lt;T\u0026gt; → CompletableFuture\u0026lt;T\u0026gt;**\n\n```java\nExecutor executor = ExecutorHelper.create(Executors.newSingleThreadExecutor());\nPromise\u003cString\u003e helloWorldPromise = executor.async(() -\u003e \"Hello\").and(s -\u003e s + \" world!\");\nCompletableFuture\u003cString\u003e completable = CompletableFutureHelper.completableFuture(helloWorldPromise);\n```\n\nIn CompletableFutureHelper **promise\u0026lt;T\u0026gt; :: CompletableFuture\u0026lt;T\u0026gt; → Promise\u0026lt;T\u0026gt;**\n\n```java\nCompletableFuture\u003cString\u003e completable = CompletableFutureHelper.supplyAsync(() -\u003e \"Hello World\");\nPromise\u003cString\u003e helloWorldPromise = CompletableFutureHelper.promise(completable);\n```\n\n## Releases\n\nThis library is available at Sonatype OSS Repository Hosting service and can be simply used adding the following \ndependency - for instance - to your pom project.\n\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003eorg.smallibs\u003c/groupId\u003e\n  \u003cartifactId\u003ehpas\u003c/artifactId\u003e\n  \u003cversion\u003e0.12.6\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## About the library design \n\nThe library has been designed simulating High Order Type in Java and self type thanks to F-Bounded quantification polymorphism. \n\nFor more information follow [this link](https://gist.github.com/jdegoes/6842d471e7b8849f90d5bb5644ecb3b2).\n\n## License\n\nCopyright (C)2016-2025 D. Plaindoux.\n\nThis program is  free software; you can redistribute  it and/or modify\nit  under the  terms  of  the GNU  Lesser  General  Public License  as\npublished by  the Free Software  Foundation; either version 2,  or (at\nyour option) any later version.\n\nThis program  is distributed in the  hope that it will  be useful, but\nWITHOUT   ANY  WARRANTY;   without  even   the  implied   warranty  of\nMERCHANTABILITY  or FITNESS  FOR  A PARTICULAR  PURPOSE.  See the  GNU\nLesser General Public License for more details.\n\nYou  should have  received a  copy of  the GNU  Lesser General  Public\nLicense along with  this program; see the file COPYING.  If not, write\nto the  Free Software Foundation,  675 Mass Ave, Cambridge,  MA 02139,\nUSA.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallibs%2Fhpas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmallibs%2Fhpas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallibs%2Fhpas/lists"}