type address = (string, int); type mapper = Closure<(T), U>; type reducer = Closure<(T, U), U>; type filter = Closure<(T), bool>; function vec_filter( vec $vec, filter $filter ): vec { $result = vec[]; foreach $vec as $item { if $filter($item) { $result[] = $item; } } return $result; } function vec_map( vec $vec, mapper $mapper ): (vec, vec) { $result = vec[]; foreach $vec as $item { $result[] = $mapper($item); } ($vec, $result) } function dict_filter( dict $dict, filter $filter ): dict { $result = dict[]; foreach $dict as $key => $item { if $filter($item) { $result[$key] = $item; } } return $result; } function dict_map( dict $dict, mapper $mapper ): (dict, dict) { $result = dict[]; foreach $dict as $key => $item { $result[$key] = $mapper($item); } ($dict, $result) } function iterable_map_to_dict( iterable $iterable, mapper $mapper ): (iterable, dict,) { $result = dict[]; foreach $iterable as $key => $item { $result[$key] = $mapper($item); } ($iterable, $result) } function iterable_filter_to_dict( iterable $iterable, filter $filter ): dict { $result = dict[]; foreach $iterable as $key => $item { if $filter($item) { $result[$key] = $item; } } return $result; }