prefer folds over pattern matching

pattern matching:
```scala
val strResult = Option(5) match { 
  case Some(v) => v.toString
  case None => "0"
}
```

fold:
```scala
val strResult = Option(5).fold("0")(_.toString)
```
This commit is contained in:
Anzori (Nika) Ghurtchumelia 2023-04-01 02:57:39 +04:00 committed by GitHub
parent ec83d01dca
commit 25b23e0f86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,10 +44,7 @@ private[hnsw] object JMapBasedIdEmbeddingMap {
injection: Injection[T, Array[Byte]],
numElements: Option[Int] = Option.empty
): IdEmbeddingMap[T] = {
val map = numElements match {
case Some(elements) => new ConcurrentHashMap[T, EmbeddingVector](elements)
case None => new ConcurrentHashMap[T, EmbeddingVector]()
}
val map = numElements.fold(new ConcurrentHashMap[T, EmbeddingVector])(elems => new ConcurrentHashMap(elems))
HnswIOUtil.loadEmbeddings(
embeddingFile,
injection,