Skip to content

Instantly share code, notes, and snippets.

@alalwww
Created July 22, 2014 18:11
Show Gist options
  • Save alalwww/91a9e6651fbc63b2fb71 to your computer and use it in GitHub Desktop.
Save alalwww/91a9e6651fbc63b2fb71 to your computer and use it in GitHub Desktop.
PlayのOptionはItelable実装してるので、判定と代入がforで書けちゃう
F.Option<Value> valueOrNull = findOptionValue();
// valueがあったら更新して返す
for (Value val : valueOrNull) {
val.update();
return val;
}
// valueがなかったらあたらしく作って初期化して保存して返す
Value newValue = new Value();
newValue.initialize();
newValue.save();
return newValue;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment