Joselo
Joselo

Reputation: 93

a better way to create a map from a list

I have a function that look like:

 def functionTrans(f: FunctionDec) = {

    // some FunctionDec manipulation

    f.name -> FuncEntry(/* something here*/)
  }

Witch basically do a manipulation of FunctionDec and turn into a Pair (String, FuncEntry). Also i have a Map[String, FuncEntry] called varsEnv and a List[FunctionDec] called decs. I need apply that manipulation to all the list and return an augmented Map. What i did looks like:

val venvWithFunction = decs.foldLeft(varsEnv)(_ + functionTrans(_))

There's a better scala-colection way to do this?

Upvotes: 0

Views: 67

Answers (1)

Ionuț G. Stan
Ionuț G. Stan

Reputation: 179098

decs.map(functionTrans _).toMap should suffice.

Upvotes: 1

Related Questions