How to make method return the same generic as the input?
问题 I want to split a string delimited by commas and use the result as either a Seq or a Set : def splitByComma(commaDelimited: String): Array[String] = commaDelimited.trim.split(',') def splitByCommaAsSet(commaDelimited: String): Set[String] = splitByComma(commaDelimited).toSet def splitByCommaAsSeq(commaDelimited: String): Seq[String] = splitByComma(commaDelimited).toSeq val foods = "sushi,taco,burrito" val foodSet = splitByCommaAsSet(foods) // foodSet: scala.collection.immutable.Set[String] =