Javaプログラマ向けモナド
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
*モナド... [#u7ee1556]
まず、自分には、理解はいいから、使えればいい。
もっというと、モナドの考え方のMaybeとStateとOptionの3つ...
具体的には、
次の関数(nextAction)を実行する前に「nullでないか確認する...
Java8では、Maybe.thenはOptional.flatMapに相当し、Maybe.Re...
**参考URL [#x19a6645]
http://the.igreque.info/posts/2016/04-monad-in-java.html
上記URLから抜粋すると
とりあえず下記のメソッドのインタフェースを用意するらしい
下記は説明用のインタフェース、わかりやすくしているが、コ...
interface Monad<T1> {
<T2> Monad<T2> then(Function<T1, Monad<T2>> action);
interface Return {
<T> Monad<T> doNothingReturning(T value);
}
}
**Maybe [#l8bc833e]
class Maybe<T1> implements Monad<T1> {
private final T1 x;
Maybe(T1 x){
this.x = x;
}
public <T2> Maybe<T2> then(Function<T1, Maybe<T2>> n...
if (x != null){
return nextAction.apply(x);
} else {
return new Maybe<>(null);
}
}
public static class Return implements Monad.Return {
public <T> Maybe<T> doNothingReturning(T x){
return new Maybe<>(x);
}
}
}
** ちゃんとしてるらしいけど、こだわりのプログラムのサンプ...
https://github.com/highj/highj
** わかりやすいサンプルコードの場所 [#gc7e3332]
https://github.com/igrep/monad-in-java-sample
終了行:
*モナド... [#u7ee1556]
まず、自分には、理解はいいから、使えればいい。
もっというと、モナドの考え方のMaybeとStateとOptionの3つ...
具体的には、
次の関数(nextAction)を実行する前に「nullでないか確認する...
Java8では、Maybe.thenはOptional.flatMapに相当し、Maybe.Re...
**参考URL [#x19a6645]
http://the.igreque.info/posts/2016/04-monad-in-java.html
上記URLから抜粋すると
とりあえず下記のメソッドのインタフェースを用意するらしい
下記は説明用のインタフェース、わかりやすくしているが、コ...
interface Monad<T1> {
<T2> Monad<T2> then(Function<T1, Monad<T2>> action);
interface Return {
<T> Monad<T> doNothingReturning(T value);
}
}
**Maybe [#l8bc833e]
class Maybe<T1> implements Monad<T1> {
private final T1 x;
Maybe(T1 x){
this.x = x;
}
public <T2> Maybe<T2> then(Function<T1, Maybe<T2>> n...
if (x != null){
return nextAction.apply(x);
} else {
return new Maybe<>(null);
}
}
public static class Return implements Monad.Return {
public <T> Maybe<T> doNothingReturning(T x){
return new Maybe<>(x);
}
}
}
** ちゃんとしてるらしいけど、こだわりのプログラムのサンプ...
https://github.com/highj/highj
** わかりやすいサンプルコードの場所 [#gc7e3332]
https://github.com/igrep/monad-in-java-sample
ページ名: