From 5be91b845f4cdb5b6df0a31ed525f746a6038a2c Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Mon, 16 Sep 2024 17:15:05 +0200 Subject: Day 10, Part 2 --- Common/NonEmptyList.lean | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Common/NonEmptyList.lean') diff --git a/Common/NonEmptyList.lean b/Common/NonEmptyList.lean index 786e192..6e76f89 100644 --- a/Common/NonEmptyList.lean +++ b/Common/NonEmptyList.lean @@ -9,3 +9,12 @@ def toList (l : NonEmptyList α) : List α := def ofList (l : List α) (_ : ¬l.isEmpty) : NonEmptyList α := match l with | head :: tail => {head, tail} + +def ofList? (l : List α) : Option $ NonEmptyList α := + if h : l.isEmpty then + none + else + ofList l h + +instance [ToString α] : ToString (NonEmptyList α) where + toString := List.toString ∘ toList -- cgit v1.2.3