General

Profile

EdvardM (Edvard Majakari)

Issues

open closed Total
Assigned issues 0 0 0
Reported issues 0 1 1

Activity

11/23/2011

10:18 PM Ruby Feature #5662: inject-accumulate, or Haskell's mapAccum*
Ok.. I'll give real example to show what is typical use case for us:
hash = MyDatabaseObject.get_all.infuse({}) { |h, r| h[normalize_db_key(r.id, r.name)] = r }
after that, code can quickly access any record by id and name saying
obj ...
EdvardM (Edvard Majakari)
04:17 PM Ruby Feature #5662: inject-accumulate, or Haskell's mapAccum*
I also noticed mapAccum* is quite different.
I have to agree with Rodrigo. (each_)with_object seems to really do the thing, but the name is a bit funny one. Then again, that could be just simply aliased in the code for accumulating.
EdvardM (Edvard Majakari)
05:24 AM Ruby Feature #5662 (Rejected): inject-accumulate, or Haskell's mapAccum*
with Ruby, we often use this idiom to build a hash out of something:
new_hash = enum.inject({}) { |h, thing| h[compute_key(thing) = compute_value(thing)]; h }
while that last h is very easy to add, it is also easy to forget and fee...
EdvardM (Edvard Majakari)

Also available in: Atom