mapv multimethod

Methods

mapv(h:Hash, mapper:Fun) Source: stdlib.ngs:3382
Map Hash values. Build new Hash with same keys as in h but values mapped by mapper.

Parameters

hSource hash
mapperFunction to be called with values

Returns

Hash

Example

LEN = 3
lines_ = read("/usr/share/dict/words").lines()
long_lines = lines_.filter({A.len()>LEN})
prefix_to_lines = long_lines.group(F(line) line[0..LEN])  # {"pfx1": ["pfx1a", "pfx1b", ...], "pfx2": ["pfx2a", "pfx2b", ...], ...}
prefix_to_count = prefix_to_lines.mapv(len)  # {"pfx1": 30, "pfx2": 35, ...}
top = prefix_to_count.Arr().sort(F(a, b) b[1] <= a[1]).Hash()
top .= limit(10)
echo(top)  # Outputs: {con=1219, dis=1001, pro=808, pre=607, com=600, int=543, tra=498, ove=431, per=422, imp=421}