mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-01 08:48:46 +02:00
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:
parent
ec83d01dca
commit
25b23e0f86
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user