Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Batteries/Data/List/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ namespace List

/-! ## New definitions -/

/-- Get the maximum element of a list.
If the given list is empty, returns `(default : α)` and produces a panic error message. -/
def max! {α} [Inhabited α] [Max α] (xs : List α) : α :=
match xs.max? with
| none => panic! "List.max! called on empty list"
| some x => x

/-- Get the minimum element of a list.
If the given list is empty, returns `(default : α)` and produces a panic error message. -/
def min! {α} [Inhabited α] [Min α] (xs : List α) : α :=
match xs.min? with
| none => panic! "List.min! called on empty list"
| some x => x

/--
Computes the "bag intersection" of `l₁` and `l₂`, that is,
the collection of elements of `l₁` which are also in `l₂`. As each element
Expand Down