Skip to content

Commit 9565d40

Browse files
committed
Publish of Github pages from Gradle.
1 parent 525f199 commit 9565d40

File tree

1 file changed

+1
-76
lines changed

1 file changed

+1
-76
lines changed

examples-java8.html

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ <h2>Java 8 Examples</h2>
101101
<li>
102102
<p><a href="#optionMap">Option map</a></p>
103103
</li>
104-
<li>
105-
<p><a href="#ioWalkthrough">IO Walkthrough</a></p>
106-
</li>
107104
</ul>
108105
</div>
109106
</div>
@@ -396,79 +393,7 @@ <h2 id="optionMap">Option Map</h2>
396393
</div>
397394
</div>
398395
</div>
399-
</div>
400-
<div class="sect1">
401-
<h2 id="ioWalkthrough">IO Walkthrough</h2>
402-
<div class="sectionbody">
403-
<div class="paragraph">
404-
<p><a href="https://github.com/functionaljava/functionaljava/blob/master/demo/src/main/java/fj/demo/IOWalkthrough.java">Github Source</a></p>
405-
</div>
406-
<div class="paragraph">
407-
<p>Demonstrates how to work with the IO type.</p>
408-
</div>
409-
<div class="listingblock">
410-
<div class="content">
411-
<pre class="prettyprint highlight"><code class="language-java" data-lang="java">
412-
// IO is just a container to defer a computation (lazy), with the intention to encapsulate computations that either
413-
// consume and/or produce side-effects
414-
// the computation is not (yet) executed on creation hence it can be treated like a value
415-
416-
final IO&lt;Unit&gt; askName = () -&gt; {
417-
System.out.println(&quot;Hi, what's your name?&quot;);
418-
return Unit.unit();
419-
};
420-
421-
// fj.data.IOFunctions contains a lot of convenience functions regarding IO, the above example could be rewritten with IOFunctions.stdoutPrintln
422-
// we now create an IO value to prompt for the name if executed
423-
424-
IO&lt;Unit&gt; promptName = IOFunctions.stdoutPrint(&quot;Name: &quot;);
425-
426-
// we can compose these two values with fj.data.IOFunctions.append, since they both are not interested in any runtime value
427-
428-
IO&lt;Unit&gt; askAndPromptName = IOFunctions.append(askName, promptName);
429-
430-
// now we create an IO value to read a line from stdin
431-
432-
final IO&lt;String&gt; readName = () -&gt; new BufferedReader(new InputStreamReader(System.in)).readLine();
433-
434-
// this is the same as IOFunctions.stdinReadLine()
435-
436-
// now we create a function which takes a string, upper cases it and creates an IO value that would print the upper cased string if executed
437-
438-
final F&lt;String, IO&lt;Unit&gt;&gt; upperCaseAndPrint = F1Functions.&lt;String, IO&lt;Unit&gt;, String&gt;o(IOFunctions::stdoutPrintln).f(String::toUpperCase);
439-
440-
// we now want to compose reading the name with printing it, for that we need to have access to the runtime value that is returned when the
441-
// IO value for read is executed, hence we use fj.data.IOFunctions.bind instead of fj.data.IOFunctions.append
442-
443-
final IO&lt;Unit&gt; readAndPrintUpperCasedName = IOFunctions.bind(readName, upperCaseAndPrint);
444-
445-
// so append is really just a specialised form of bind, ignoring the runtime value of the IO execution that was composed before us
446-
447-
final IO&lt;Unit&gt; program = IOFunctions.bind(askAndPromptName, ignored -&gt; readAndPrintUpperCasedName);
448-
449-
// this is the same as writing IOFunctions.append(askAndPromptName, readAndPrintUpperCasedName)
450-
451-
// we have recorded the entire program, but have not run anything yet
452-
// now we get to the small dirty part at the end of our program where we actually execute it
453-
// we can either choose to just call program.run(), which allows the execution to escape
454-
// or we use safe to receive an fj.data.Either with the potential exception on the left side
455-
456-
toSafeValidation(program).run().on((IOException e) -&gt; { e.printStackTrace(); return Unit.unit(); });
457-
458-
// doing function composition like this can be quite cumbersome, since you will end up nesting parenthesis unless you flatten it out by
459-
// assigning the functions to variables like above, but you can use the fj.F1W syntax wrapper for composing single-argument functions and fj.data.IOW
460-
// for composing IO values instead, the entire program can be written like so:
461-
462-
IOW.lift(stdoutPrintln(&quot;What's your name again?&quot;))
463-
.append(stdoutPrint(&quot;Name: &quot;))
464-
.append(stdinReadLine())
465-
.bind(F1W.lift((String s) -&gt; s.toUpperCase()).andThen(IOFunctions::stdoutPrintln))
466-
.safe().run().on((IOException e) -&gt; { e.printStackTrace(); return Unit.unit(); });
467-
</code></pre>
468-
</div>
469-
</div>
470-
</div>
471-
</div></p>
396+
</div></p>
472397
</article>
473398
</div> <!-- /.col-md-12 -->
474399
</div> <!-- /.row -->

0 commit comments

Comments
 (0)