Documentation

CslibFrontier.Foundations.Control.Monad.FilterM

Monadic filtering with pure tests and under monad morphisms #

Core List.filterM p xs runs the effectful test p once on each element of xs, from left to right, and keeps the accepted elements in order. Core proves little about it. This module records the two facts that let a program written with List.filterM be run purely and transported along monad morphisms. Core defines List.filterM through the accumulator List.filterAuxM without exposing the body, so this module imports Init.Data.List.Control with import all, as core's own Init.Data.List.Monadic does.

Main results #

@[simp]
theorem List.filterM_pure {α : Type} {m : Type → Type u_1} [Monad m] [LawfulMonad m] (p : α → Bool) (xs : List α) :
filterM (fun (x : α) => pure (p x)) xs = pure (filter p xs)

With pure tests, core List.filterM is List.filter.

theorem Cslib.IsMonadHom.map_filterM {α : Type} {m : Type → Type u_1} {n : Type → Type u_2} [Monad m] [Monad n] {f : {γ : Type} → m γ → n γ} (hf : IsMonadHom m n fun {α : Type} => f) (p : α → m Bool) (xs : List α) :
f (List.filterM p xs) = List.filterM (fun (x : α) => f (p x)) xs

Monad morphisms commute with core List.filterM.