lib: lists: add countValues
This commit is contained in:
parent
7d2c43d157
commit
906202b222
|
@ -1,8 +1,22 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) filter;
|
||||
inherit (lib) filter foldl';
|
||||
in
|
||||
{
|
||||
# Count the number of appararitions of each value in a list.
|
||||
#
|
||||
# countValues ::
|
||||
# [ any ] -> ({ any = int; })
|
||||
countValues =
|
||||
let
|
||||
addToCount = acc: x:
|
||||
let
|
||||
v = toString x;
|
||||
in
|
||||
acc // { ${v} = (acc.${v} or 0) + 1; };
|
||||
in
|
||||
foldl' addToCount { };
|
||||
|
||||
# Filter a list using a predicate function after applying a map.
|
||||
#
|
||||
# mapFilter ::
|
||||
|
|
Loading…
Reference in a new issue