summaryrefslogtreecommitdiff
path: root/Common/NonEmptyList.lean
diff options
context:
space:
mode:
Diffstat (limited to 'Common/NonEmptyList.lean')
-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