1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Scala] Futureのメソッドたち

Last updated at Posted at 2024-11-08

メソッド一覧

使ったことがあるものを随時追加していく。

メソッド名 Success vs Failure  型 メモ
map Success値へ適応 TODO 成功値を成功値へ変換する
handle Failure値へ適応 TODO エラー値を成功値へ変換する
onSuccess Success値を受け取る TODO 副作用(println等)の処理を行う。-> 値に変更はなし。
onFailure Failure値を受け取る TODO 副作用(println等)の処理を行う。-> 値に変更はなし。

使い方の例

myRequestFuture
  .onSuccess(logRequestSuccess)        // Future[Response] ⭐️side effect only
  .onFailure(logRequestFailure)        // Future[Response] ⭐️side effect only
  .handle(raiseCustomError)            // Future[Response]
  .map(parseJsonResponse)              // Future[Json]
  .map(Post.buildFromResponseJson)     // Future[Post]
  .onFailure(logCustomError)           // Future[Post]     ⭐️side effect only

Ref.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?