Discord is now Scala’s main chat platform. Please join us at https://discord.com/invite/scala
"x".->(2)
sealed trait AssignmentTo
case class Constant(c: Int) extends AssignmentTo
case class Variable(varName: String) extends AssignmentTo
Seq[(String, AssignmentTo)](
"x" -> Constant(1),
"y" -> Constant(2),
"z" -> Constant(3),
"uhoh" -> Variable("x"),
"x" -> Constant(1),
"uhoh" -> Variable("x")
).foldLeft(Map.empty[String, Int]) { case (acc, (ident, assign)) =>
val newValue = assign match {
case Constant(c) => c
case Variable(varName) => acc(varName)
}
acc + ((ident, newValue))
}
98 + 1 = 100
"
"x"
to 1