4 ms·
I prefer Ruby's syntax too, but Swift also has a shorthand version which is, IMO, usually nicer. groceriesByDepartment.mapValues { $0.count }
by smitherfield 9y ago
I prefer Ruby's syntax too, but Swift also has a shorthand version which is, IMO, usually nicer.
groceriesByDepartment.mapValues { $0.count }
- jakobegger 9y agoThe shorthand version doesn‘t let you specify argumen types (only works when they can be inferred)
- mantas 9y agoWhich is vast majority of cases. Unless you work with a lot of legacy ObjC code.
- Groxx 9y agostuff like this always makes me miss Ruby's even-shorter-hand version though :) groceriesByDepartment.mapValues(&:count) # not ruby, but meh