Nix 101 Course / Section 2: The Nix language
Premium

2.9 Common idioms: map, filter, foldl' and friends

Lesson 16 of 68 · 11:39

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

About this lesson

You could write every list operation recursively by hand, but you should not have to. This lesson introduces map, filter and foldl', the everyday idioms of functional programming in Nix, and shows where the huge nixpkgs standard library documents hundreds more.

In this video

  • builtins.filter and map in the REPL, plus a first taste of eta reduction
  • The sum function from the exercise, rewritten in one line with foldl'
  • Why Nix has three manuals, and which one to open for what
  • noogle.dev, a search engine for Nix functions, with examples and links straight into the nixpkgs source
  • The three library files that hold about 80 percent of the functions you will ever need

After this lesson

You stop reinventing the wheel: before writing a helper yourself, you know exactly where to check whether nixpkgs already ships it.

Builds on: Exercise: sum a list with recursion (2.13)

Links: