0

I saw some code like this. From REPL test, it looks like "/:" iterates through chars and call incr repeatedly. But I can't find any document for this syntax. What does /: syntax mean here?

val chars = List('a','b')
def incr(acc:Map[Char, Int], c:Char) = {
   val count = (acc get c).getOrElse(0) + 1
    acc + ((c, count))
}

(Map[Char,Int]() /: chars)(incr)
3
  • 3
    check the scaladoc for Map ;) scala-lang.org/api/current/index.html#scala.collection.Map@/… Commented Sep 3, 2016 at 18:16
  • Looks like it is foldLeft right? Commented Sep 3, 2016 at 18:27
  • It's just a method call like any other method call. It's not special syntax. Very few things in Scala are, in fact. Commented Sep 4, 2016 at 13:16

1 Answer 1

1

From the documentation:

   *  Note: `/:` is alternate syntax for `foldLeft`; `z /: xs` is the same as
   *  `xs foldLeft z`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.