Non-Empty Lists #
Here, we define non-empty lists based on regular lists.
Basically a NonEmptyList is a List without the nil constructor.
- cons {α : Type u} (hd : α) (tl : List α) : NonEmptyList α
Instances For
We can convert a NonEmptyList to a regular List in the obvious way.
Equations
- (CustomBasicDatastructures.NonEmptyList.cons hd tl).toList = hd :: tl
Instances For
A List obtained from a NonEmptyList is not empty as expected.
We can build a NonEmptyList from a regular List as long as we know that the list is not empty.
Equations
Instances For
Construct a NonEmptyList from a single element and a NonEmptyList.
Equations
Instances For
Transforming a cons' into a list yields the expected list.
Alternative cases eliminator.
Equations
- CustomBasicDatastructures.NonEmptyList.cases (CustomBasicDatastructures.NonEmptyList.cons a []) singleton cons' = singleton a
- CustomBasicDatastructures.NonEmptyList.cases (CustomBasicDatastructures.NonEmptyList.cons a (a' :: as)) singleton cons' = cons' a (CustomBasicDatastructures.NonEmptyList.cons a' as)
Instances For
Alternative induction principle.
Equations
- One or more equations did not get rendered due to their size.
- CustomBasicDatastructures.NonEmptyList.rec' (CustomBasicDatastructures.NonEmptyList.cons a []) singleton cons' = singleton a
Instances For
Extract first element from NonEmptyList.
Equations
- (CustomBasicDatastructures.NonEmptyList.cons hd tl).head = hd
Instances For
We can express head in terms of the regular list obtained through toList.
Extract all but the first element from NonEmptyList. This returns a plain List.
Equations
- (CustomBasicDatastructures.NonEmptyList.cons hd tl).tail = tl
Instances For
We can express tail in terms of the regular list obtained through toList.