Lists bookended by replicate blocks #
Generic facts about replicate m a ++ l ++ replicate n b — a list with a left bookend
of m copies of a, a middle l, and a right bookend of n copies of b — and how
take, rtake, filter, and Sublist interact with the bookends. These flesh out
the replicate/append corner of the List API and are candidates for
Mathlib/Data/List/.
Main results #
List.take_replicate_append/List.rtake_append_replicate— a shorttake/rtakereaches only into the adjacent bookend, returning itsreplicate.List.filter_replicate_append_replicate— filtering distributes over the bookends, each width collapsing to0when its element is filtered out.List.sublist_replicate_append_replicate/List.not_sublist_replicate_append_replicate— a middle-sublist embeds, and a pattern that can borrow neither bookend's element for its head or last must come from the middle.
A take no longer than the left bookend reaches only into it.
An rtake no longer than the right bookend reaches only into it.
Filtering distributes over both bookends; a bookend width collapses to 0 when its
element fails the predicate.
A sublist of the middle is a sublist of the bookended list.
A pattern whose head is not a and whose last element is not b, and which is not a
sublist of the middle, is not a sublist of the bookended list: the replicate blocks can
supply neither its head nor its last element, so any embedding must lie in the middle.