type Predicate = Closure<(T), bool>; function filter(vec $vec, Predicate $predicate): vec { $result = vec[]; foreach $vec as $item { if $predicate($item) { $result[] = $item; } } return $result; } type Mapper = Closure<(K, V), U>|SomeOtherType; function map(dict $dict, Mapper $mapper): dict { $result = dict[]; if $mapper is SomeOtherType<_, _, _> { foreach $dict as $key => $value { $result[$key] = $mapper->doMap($key, $value); } } else { foreach $dict as $key => $value { $result[$key] = $mapper($key, $value); } } return $result; }