2 added 1 character in body
source | link

Some suggestions to improve your code:

xs.sortWith((e1, e2) => (e1 < e2)) is identical to xs.sorted

If you are not interested in Stem.word you can place it into companions' apply-method:

object Stem {
  def apply(word: String): Stem = {
    val stem: List[Char] = word.toLowerCase.trim.toList.sorted
    new Stem(stem)
  }
}

case class Stem private(stem: List[Char])

source.mkString.split('\n') is identical to source.getLines


Whenever you wannawant to sum-up something oreor use an accumulator, fold is what you are searching for:

(Map.empty[Stem, Set[String]] /: words) {
  case (map, word) => map + (Stem(word) -> Set(word))
}

With help of scalaz:

words.map(word => Map(Stem(word) -> Set(word))) reduceLeft { _|+|_ }

reduce is a fold: xs.tail.fold(xs.head)(f)

/: is a synonym for foldLeft: (init /: xs)(f) == (xs foldLeft init)(f)


Your implicit conversion String => Stem doesn't work in string -> set because -> already needs an implicit conversion and you are not allowed to apply multiple ones at once. When you use tuple notation (string, set), your implicit conversion is applied.

Some suggestions to improve your code:

xs.sortWith((e1, e2) => (e1 < e2)) is identical to xs.sorted

If you are not interested in Stem.word you can place it into companions' apply-method:

object Stem {
  def apply(word: String): Stem = {
    val stem: List[Char] = word.toLowerCase.trim.toList.sorted
    new Stem(stem)
  }
}

case class Stem private(stem: List[Char])

source.mkString.split('\n') is identical to source.getLines


Whenever you wanna sum-up something ore use an accumulator, fold is what you are searching for:

(Map.empty[Stem, Set[String]] /: words) {
  case (map, word) => map + (Stem(word) -> Set(word))
}

With help of scalaz:

words.map(word => Map(Stem(word) -> Set(word))) reduceLeft { _|+|_ }

reduce is a fold: xs.tail.fold(xs.head)(f)

/: is a synonym for foldLeft: (init /: xs)(f) == (xs foldLeft init)(f)


Your implicit conversion String => Stem doesn't work in string -> set because -> already needs an implicit conversion and you are not allowed to apply multiple ones at once. When you use tuple notation (string, set), your implicit conversion is applied.

Some suggestions to improve your code:

xs.sortWith((e1, e2) => (e1 < e2)) is identical to xs.sorted

If you are not interested in Stem.word you can place it into companions' apply-method:

object Stem {
  def apply(word: String): Stem = {
    val stem: List[Char] = word.toLowerCase.trim.toList.sorted
    new Stem(stem)
  }
}

case class Stem private(stem: List[Char])

source.mkString.split('\n') is identical to source.getLines


Whenever you want to sum-up something or use an accumulator, fold is what you are searching for:

(Map.empty[Stem, Set[String]] /: words) {
  case (map, word) => map + (Stem(word) -> Set(word))
}

With help of scalaz:

words.map(word => Map(Stem(word) -> Set(word))) reduceLeft { _|+|_ }

reduce is a fold: xs.tail.fold(xs.head)(f)

/: is a synonym for foldLeft: (init /: xs)(f) == (xs foldLeft init)(f)


Your implicit conversion String => Stem doesn't work in string -> set because -> already needs an implicit conversion and you are not allowed to apply multiple ones at once. When you use tuple notation (string, set), your implicit conversion is applied.

1
source | link

Some suggestions to improve your code:

xs.sortWith((e1, e2) => (e1 < e2)) is identical to xs.sorted

If you are not interested in Stem.word you can place it into companions' apply-method:

object Stem {
  def apply(word: String): Stem = {
    val stem: List[Char] = word.toLowerCase.trim.toList.sorted
    new Stem(stem)
  }
}

case class Stem private(stem: List[Char])

source.mkString.split('\n') is identical to source.getLines


Whenever you wanna sum-up something ore use an accumulator, fold is what you are searching for:

(Map.empty[Stem, Set[String]] /: words) {
  case (map, word) => map + (Stem(word) -> Set(word))
}

With help of scalaz:

words.map(word => Map(Stem(word) -> Set(word))) reduceLeft { _|+|_ }

reduce is a fold: xs.tail.fold(xs.head)(f)

/: is a synonym for foldLeft: (init /: xs)(f) == (xs foldLeft init)(f)


Your implicit conversion String => Stem doesn't work in string -> set because -> already needs an implicit conversion and you are not allowed to apply multiple ones at once. When you use tuple notation (string, set), your implicit conversion is applied.