Skip to content

Commit 3698355

Browse files
authored
Merge pull request #147 from colehaus/tails
Add `tails`
2 parents 66be7a2 + 9ed99f1 commit 3698355

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Data/List.purs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,16 @@ partition p xs = foldr select { no: Nil, yes: Nil } xs
617617
then { no, yes: x : yes }
618618
else { no: x : no, yes }
619619

620+
-- | Returns all final segments of the argument, longest first. For example,
621+
-- |
622+
-- | ```purescript
623+
-- | tails (1 : 2 : 3 : Nil) == ((1 : 2 : 3 : Nil) : (2 : 3 : Nil) : (3 : Nil) : (Nil) : Nil)
624+
-- | ```
625+
-- | Running time: `O(n)`
626+
tails :: forall a. List a -> List (List a)
627+
tails Nil = singleton Nil
628+
tails list@(Cons _ tl)= list : tails tl
629+
620630
--------------------------------------------------------------------------------
621631
-- Set-like operations ---------------------------------------------------------
622632
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)