From 5dcd67b8625833f0776616fd1049460b4fdf5d21 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 23 Apr 2017 21:37:22 +0100 Subject: [PATCH] README.adoc: add documentation for Value Also add badges for build status and code coverage. --- README.adoc | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 132 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 5cc2b63..895bb64 100644 --- a/README.adoc +++ b/README.adoc @@ -1,8 +1,15 @@ # Conditional -If-then-else in a functional-style. +image:https://travis-ci.org/kemitix/conditional.svg?branch=master["Build Status", link="https://travis-ci.org/kemitix/conditional"] -## Usage +image::https://coveralls.io/repos/github/kemitix/conditional/badge.svg?branch=master["Coverage Status", link="https://coveralls.io/github/kemitix/conditional?branch=master"] + +* link:#_condition[Condition] +* link:#_value[Value] + +## Condition + +If-then-else in a functional-style. ### if-then @@ -169,3 +176,126 @@ Condition.where(isTrue()) .and(isAlsoTrue()) .then(() -> doSomethingElse()); ---- + +## Value + +Values from an if-then-else in a functional-style. + +Functional, and verbose, alternative to the ternary operator (`?:`). + +### if-then-else + +[[source,java]] +---- +String result; +if (isTrue()) { + result = TRUE; +} else { + result = FALSE; +} +---- + +[[source,java]] +---- +String result = isTrue() ? TRUE : FALSE; +---- + +[[source,java]] +---- +final String result = Value.where(isTrue()).then(() -> TRUE) + .otherwise(() -> FALSE); +---- + +### if-not-then-else + +[[source,java]] +---- +String result; +if (!isTrue()) { + result = TRUE; +} else { + result = FALSE; +} +---- + +[[source,java]] +---- +final String result = Value.whereNot(isTrue()).then(() -> TRUE) + .otherwise(() -> FALSE); +---- + +### if-and-then-else + +[[source,java]] +---- +String result; +if (isTrue() && alternativeIsTrue()) { + result = TRUE; +} else { + result = FALSE; +} +---- + +[[source,java]] +---- +final String result = Value.where(isTrue()).and(alternativeIsTrue()) + .then(() -> TRUE) + .otherwise(() -> FALSE); +---- + +### if-and-not-then-else + +[[source,java]] +---- +String result; +if (isTrue() && !alternativeIsFalse()) { + result = TRUE; +} else { + result = FALSE; +} +---- + +[[source,java]] +---- +final String result = Value.where(isTrue()).andNot(alternativeIsFalse()) + .then(() -> TRUE) + .otherwise(() -> FALSE); +---- + +### if-or-then-else + +[[source,java]] +---- +String result; +if (isTrue() || alternativeIsTrue()) { + result = TRUE; +} else { + result = FALSE; +} +---- + +[[source,java]] +---- +final String result = Value.where(isTrue()).or(alternativeIsTrue()) + .then(() -> TRUE) + .otherwise(() -> FALSE); +---- + +### if-or-not-then-else + +[[source,java]] +---- +String result; +if (isTrue() || !isFalse()) { + result = TRUE; +} else { + result = FALSE; +} +---- + +[[source,java]] +---- +final String result = Value.where(isTrue()).orNot(isFalse()) + .then(() -> TRUE) + .otherwise(() -> FALSE); +----