snoyberg / mono-traversable

Type classes for mapping, folding, and traversing monomorphic containers
152 stars 61 forks source link

Add functions inits, tails, and initTails #213

Closed BebeSparkelSparkel closed 4 months ago

BebeSparkelSparkel commented 1 year ago

Many of the supported types have the functions inits :: a -> [a] and tails :: a -> [a] which are very useful, but they are missing from mono-traversable.

If there is not a native inits and tails defined for the type there is an easy default implementation leveraging initMay and tailMay which are already defined in mono-traversable.

I also think including initTails :: a -> [(a,a)] (a zip of inits and tails) would be helpful so that types like [a] and Seq a can have a faster implementation to get the list of splits.

Let me know if this is something you would be interested in me implementing for mono-traversable.

snoyberg commented 1 year ago

No objection from me.