@@ -3,7 +3,7 @@ module List.Extra exposing
33 , intercalate, transpose, subsequences, permutations, interweave, cartesianProduct, uniquePairs
44 , foldl1, foldr1, indexedFoldl, indexedFoldr, Step (..) , stoppableFoldl
55 , scanl, scanl1, scanr, scanr1, mapAccuml, mapAccumr, unfoldr, iterate, initialize, cycle, reverseRange
6- , splitAt, splitWhen, takeWhileRight, dropWhileRight, span, break, stripPrefix, group, groupWhile, inits, tails, conditional, select, selectSplit, gatherEquals, gatherEqualsBy, gatherWith, subsequencesNonEmpty, frequencies
6+ , splitAt, splitWhen, takeRight , dropRight , takeWhileRight, dropWhileRight, span, break, stripPrefix, group, groupWhile, inits, tails, conditional, select, selectSplit, gatherEquals, gatherEqualsBy, gatherWith, subsequencesNonEmpty, frequencies
77 , isPrefixOf, isSuffixOf, isInfixOf, isSubsequenceOf, isPermutationOf
88 , notMember, find, elemIndex, elemIndices, findIndex, findIndices, findMap, count
99 , zip, zip3
@@ -37,7 +37,7 @@ module List.Extra exposing
3737
3838# Sublists
3939
40- @docs splitAt, splitWhen, takeWhileRight, dropWhileRight, span, break, stripPrefix, group, groupWhile, inits, tails, conditional, select, selectSplit, gatherEquals, gatherEqualsBy, gatherWith, subsequencesNonEmpty, frequencies
40+ @docs splitAt, splitWhen, takeRight, dropRight, takeWhileRight, dropWhileRight, span, break, stripPrefix, group, groupWhile, inits, tails, conditional, select, selectSplit, gatherEquals, gatherEqualsBy, gatherWith, subsequencesNonEmpty, frequencies
4141
4242
4343# Predicates
@@ -1592,6 +1592,32 @@ splitWhen predicate list =
15921592 |> Maybe . map ( \ i -> splitAt i list)
15931593
15941594
1595+ {- | Take the last _n_ members of a list.
1596+
1597+ take 2 [ 1, 2, 3, 4, 5 ] == [ 1, 2 ]
1598+
1599+ -}
1600+ takeRight : Int -> List a -> List a
1601+ takeRight n lst =
1602+ lst
1603+ |> List . reverse
1604+ |> List . take n
1605+ |> List . reverse
1606+
1607+
1608+ {- | Drop the last _n_ members of a list.
1609+
1610+ dropRight 2 [ 1, 2, 3, 4, 5 ] == [ 1, 2, 3 ]
1611+
1612+ -}
1613+ dropRight : Int -> List a -> List a
1614+ dropRight n lst =
1615+ lst
1616+ |> List . reverse
1617+ |> List . drop n
1618+ |> List . reverse
1619+
1620+
15951621{- | Take elements from the right, while predicate still holds.
15961622
15971623 takeWhileRight ((<) 5) (List.range 1 10)
0 commit comments