Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Smalltalk

Idiom #189 Filter and transform list

Produce a new list y containing the result of the function T applied to all elements e of the list x that match the predicate P.

y := x 
  collect: [:ea | ea t]
  thenSelect: [:ea | ea p].

Applies the transformation T, then matches the predicate P.
y := x 
  select: [:ea | ea p]
  thenCollect: [:ea | ea t].


Matches the predicate P, then applies the transformation T.
(def y 
  (eduction (filter P)
            (map T))
            x)

New implementation...