All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mperry.fg.IOConstants.groovy Maven / Gradle / Ivy

There is a newer version: 0.8
Show newest version
package com.github.mperry.fg;

import fj.Unit
import fj.data.Option
import groovy.transform.TypeChecked;

/**
 * Created with IntelliJ IDEA.
 * User: MarkPerry
 * Date: 8/11/13
 * Time: 10:21 AM
 * To change this template use File | Settings | File Templates.
 */
@TypeChecked
class IOConstants {

	static Option console() {
		Option.fromNull(System.console())
	}

	static SimpleIO stdinReadLine() {
		new SimpleIO() {
			String run() {
				System.in.newReader().readLine()
			}
		}
	}

	static SimpleIO> consoleReadLineOption() {
		new SimpleIO>() {
			Option run() {
				Option.fromNull(System.in.withReader { java.io.Reader it ->
					it.readLine()
				})
			}
		}
	}

	static SimpleIO stdoutWriteLine(final String msg) {
		new SimpleIO() {
			Unit run() {
				println(msg)
				Unit.unit()
			}
		}
	}

    static SimpleIO empty() {
        new SimpleIO() {
            Unit run() {
                Unit.unit()
            }
        }
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy