summaryrefslogtreecommitdiff
path: root/Common
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2024-09-16 17:15:05 +0200
committerAndreas Grois <andi@grois.info>2024-09-16 17:15:05 +0200
commit5be91b845f4cdb5b6df0a31ed525f746a6038a2c (patch)
tree5a74d797e639ef9841e1e3e41d3c9c17b78dc397 /Common
parent17721b8aa7a5b78a80b6d622f90e3c1827bd4676 (diff)
Day 10, Part 2
Diffstat (limited to 'Common')
-rw-r--r--Common/NonEmptyList.lean9
1 files changed, 9 insertions, 0 deletions
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