Skip to content

Instantly share code, notes, and snippets.

@fkmhrk
Created March 2, 2017 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fkmhrk/e8d4977fc1d6c22bc5a717b339074678 to your computer and use it in GitHub Desktop.
Save fkmhrk/e8d4977fc1d6c22bc5a717b339074678 to your computer and use it in GitHub Desktop.
Method chain vs sequential statements
// We often see sequential method call.
AlertDialog.Builder builer = new AlertDialog.Builder(this);
builer.setTitle("タイトル");
builer.setMessage("メッセージ");
builer.setPositiveButton(android.R.string.ok, this.listener);
// We can use method chain.
AlertDialog.Builder builer = new AlertDialog.Builder(this);
.setTitle("タイトル")
.setMessage("メッセージ")
.setPositiveButton(android.R.string.ok, this.listener);
// We often use method chain in RxJava/Promise
Observable<Moke> o = this.sendRequest(...)
.map(new Function<>{...})
.map(new Function<>{...});
// In this case, if we use sequential method call...
Observable<Moke> o = this.sendRequest(...);
o = o.map(new Function<>{...}); // o becomes another object
o = o.map(new Function<>{...}); // o becomes another object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment