Scala best way of turning a Collection into a Map-by-key? October 25, 2022 by Tarik You can use c map (t => t.getP -> t) toMap but be aware that this needs 2 traversals.