Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/relrod/pureio-java
Various experiments with purely functional I/O in Java using free monads (and trampolines).
https://github.com/relrod/pureio-java
Last synced: 13 days ago
JSON representation
Various experiments with purely functional I/O in Java using free monads (and trampolines).
- Host: GitHub
- URL: https://github.com/relrod/pureio-java
- Owner: relrod
- License: bsd-2-clause
- Created: 2014-03-25T19:26:44.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-29T05:58:15.000Z (over 8 years ago)
- Last Synced: 2024-10-04T18:39:05.708Z (about 1 month ago)
- Language: Java
- Homepage: https://relrod.github.io/pureio-java
- Size: 345 KB
- Stars: 7
- Watchers: 7
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/relrod/pureio-java.svg?branch=master)](https://travis-ci.org/relrod/pureio-java)
Experiments with purely functional IO in Java 8.
This is standalone and doesn't depend on FJ right now, though it probably
should. As such, it re-implements several classes that are commonplace in FJ.This is experimental, you probably don't want to use it right now.
That being said:
License: **BSD-2**.
## Example
```java
public class Hello {
private static PureIO program =
TerminalLib.putStrLn("What is your name?")
.flatMap(unused0 -> TerminalLib.readLine()
.flatMap(name -> TerminalLib.putStrLn("Hi there, " + name + "! How are you?")
.flatMap(unused1 -> TerminalLib.readLine()
.flatMap(resp -> TerminalLib.putStrLn("I am also " + resp + "!")
.flatMap(unused2 -> TerminalLib.exit(0))))));public static void main(String[] args) {
UnsafePerformIO.unsafePerformIO(program);
}
}
```See more examples in `pureio-examples/`. You might even be able to run them by
doing `sbt pureio-examples/run`, if luck is going your way.## Building it (Assuming a typical Linux environment)
You need [sbt](https://raw.githubusercontent.com/paulp/sbt-extras/master/sbt)
0.13+ and Java 8. Just download the script, `chmod +x sbt` and place it
somewhere in your `$PATH`.Once you have sbt installed, you should be able to do this:
```
PATH=/usr/lib/jvm/java-1.8.0-openjdk.x86_64/bin/:$PATH sbt -java-home /usr/lib/jvm/java-1.8.0-openjdk.x86_64/ pureio-examples/run
```For convenience, you can add this to your bash_profile for future use:
```
alias sbt8='PATH=/usr/lib/jvm/java-1.8.0-openjdk.x86_64/bin/:$PATH sbt -java-home /usr/lib/jvm/java-1.8.0-openjdk.x86_64/'
```and then use `sbt8 pureio-examples/run` to run the examples.
## Building it (Windows-ish)
Windows Cygwin/MinGW support for building is experimental. We apparently can't
use paulp's sbt script because it requires Bash 4 while MinGW defaults to Bash
3. That said, you should be able to follow the instructions on the
[sbt website](http://www.scala-sbt.org/0.13/tutorial/Manual-Installation.html#Windows)
with minimal difficulty, after installing Java 8.Once you have a working `sbt` command, you can proceed as normal, and use
`sbt pureio-examples/run` to run the examples.## JavaDoc
[View javadoc](https://codeblock.github.io/pureio-java/).