0

サイズをカウントする必要がある Web リクエストの将来の結果があります。現在の応答に項目がある場合は、次のセットを取得するために別の要求を行う必要があります。現在の応答が空の場合は、完了です。

私が今持っているコード:

def list(prefix: String, lastItem: Option[String] = None, last: Seq[BucketItem] = Nil):  Future[Iterable[BucketItem]] = {
  Logger.debug(s"list :: prefix=$prefix, lastItem=$lastItem, lastItems=${last.size}")
  for {
    current <- s3.get(name, None, Some(prefix), delimiter, lastItem, None) map listResponse // type is Seq[BucketItem]
    next <- list(prefix, Some(current.last.name), last ++ current) if !(current.isEmpty)
  } yield last ++ current
}

これは、現在の要素がなくなるまではうまくいくようで、current.last.name を取得しようとして NoSuchElementException が発生します。

!(current.isEmpty) がフィルターに展開される場合の条件を理解しているので、ここで本当に欲しいものではありません。私が欲しいのは:

sequentially:
eval current
if current has more items, recursively call list to get the next set of items
yield the concatenated sequence of the right type (all the previous entries plus the last0

ここでは、先物の収集を簡単に処理するために for 内包表記を使用しています (少なくとも、これは私が過去に行った方法です)。ガイダンス/読むべきものはありますか?私はscalaにかなり慣れていないので、優しくしてください。

4

2 に答える 2