Documentation

BasicLeanDatastructures.List.NonEmpty

Non-Empty Lists #

Here, we define non-empty lists based on regular lists.

Basically a NonEmptyList is a List without the nil constructor.

Instances For

    We can convert a NonEmptyList to a regular List in the obvious way.

    Equations
    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
        @[simp]

        Transforming a singleton into a list yields a singleton list.

        @[simp]

        Transforming a cons' into a list yields the expected list.

        def CustomBasicDatastructures.NonEmptyList.cases {α : Type u} {motive : NonEmptyList α → Sort v} (l : NonEmptyList α) (singleton : (a : α) → motive (singleton a)) (cons' : (a : α) → (as : NonEmptyList α) → motive (cons' a as)) :
        motive l

        Alternative cases eliminator.

        Equations
        Instances For
          @[irreducible]
          def CustomBasicDatastructures.NonEmptyList.rec' {α : Type u} {motive : NonEmptyList α → Sort v} (l : NonEmptyList α) (singleton : (a : α) → motive (singleton a)) (cons' : (a : α) → (as : NonEmptyList α) → motive as → motive (cons' a as)) :
          motive l

          Alternative induction principle.

          Equations
          Instances For

            Extract first element from NonEmptyList.

            Equations
            Instances For

              We can express head in terms of the regular list obtained through toList.

              @[simp]

              The head of a singleton is the single value.

              @[simp]
              theorem CustomBasicDatastructures.NonEmptyList.head_cons' {α : Type u} {a : α} {as : NonEmptyList α} :
              (cons' a as).head = a

              The head of a cons' is the first value.

              Extract all but the first element from NonEmptyList. This returns a plain List.

              Equations
              Instances For

                We can express tail in terms of the regular list obtained through toList.

                @[simp]

                The tail of a singleton is empty.

                @[simp]

                The tail of a cons' is everything but the first value.