RecipesCatalogScalaRecipesPerformanceOn this pagePerformance Recipes Prefer .view.mapValues for Scala 2.13+ Prefer Vector or prepend for append-heavy workloads Replace .head with .headOption Replace .last with .lastOption Replace filter then size with count Replace map then flatten with flatMap Use isEmpty instead of size == 0 Use nonEmpty instead of size > 0