query
On this page

groupBy

lib.lists.groupBy

Primop
Docs pulled from | This Revision | 14 minutes ago

Takes 2 arguments

f, list


Groups elements of list together by the string returned from the function f called on each element. It returns an attribute set where each attribute value contains the elements of list that are mapped to the same corresponding attribute name returned by f.

For example,

builtins.groupBy (builtins.substring 0 1) ["foo" "bar" "baz"]

evaluates to

{ b = [ "bar" "baz" ]; f = [ "foo" ]; }

Noogle detected

Aliases

Detected Type
groupBy :: (a -> b) -> [a] -> AttrSet

Implementation

This function is implemented in c++ and is part of the native nix runtime.