concept console in category functional programming

appears as: console
Functional Programming in Java: How functional techniques improve your Java programs

This is an excerpt from Manning's book Functional Programming in Java: How functional techniques improve your Java programs.

  • No printing to the console or to any device
  • This is very neat and safe. No bad things can happen; no exceptions can be thrown. This is the beauty of functional programming: you have a program that will always work, whatever data you use as input. But the question is, how can you use this result? Suppose you want to display the result on the console—how can you do this?

    To see your new methods in action, use the following Console class.

    Listing 13.11. The Console class

    It’s important to note that these two methods are purely functional. They don’t throw any exceptions, nor do they read from or print to the console. They only return programs that do those things.

    Listing 13.17. The new Console class using the stack-safe version

    13.2.1. Reading data from the console

    As an example, you’ll read data from the console in a way that, although imperative, allows testing by making your programs deterministic. The approach you’ll use is similar to what you did with the random generator in chapter 12.

    sitemap

    Unable to load book!

    The book could not be loaded.

    (try again in a couple of minutes)

    manning.com homepage
    test yourself with a liveTest