Created
September 5, 2012 05:08
-
-
Save yoshihiro503/3630859 to your computer and use it in GitHub Desktop.
OptionMonad_Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fj.F; | |
import fj.Unit; | |
import fj.data.Option; | |
public class Main { | |
static void take1() { | |
for (final String s : foo()) { | |
for (final Float f : bar()) { | |
for (final Integer i : baz()) { | |
System.out.println(s+f+i); | |
}}} | |
} | |
static Option<String> foo() { | |
return Option.some("foo"); | |
} | |
static Option<Float> bar() { | |
return Option.some(0.1f); | |
} | |
static Option<Integer> baz() { | |
return Option.some(5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
失敗するかもしれない3つの処理(foo, bar, baz)をつなげたいときはfor式が便利!ただし、最後はUnit(Void)に限る。