Hi everyone,

About twice a week I start looking for a straightforward way to
turn a list of associations into a dictionary, spend a while searching,
and give up, ending up with a messy explicit loop.

Example:

   | words lengths |
   words := #('abc' 'defg').
   lengths := Dictionary new.
   words do:
      [ :each | lengths at: each put: each size ].
   lengths

Is there really no way to this with less code? I'd expect the following
to work:

   | words lengths |
   words := #('abc' 'defg').
   lengths := Dictionary withAll:
      (words collect: [ :each | each -> each size ]).

but it looks like Dictionary>>#withAll: was specifically designed to
make this impossible (because with the default implementation in
Collection it would work).

Konrad.

Reply via email to