Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/List/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ module List.Extra
, greedyGroupsOf
, greedyGroupsOfWithStep
, groupsOfVarying
, removeSubsequentDuplicates
)

{-| Convenience functions for working with List


# Basics

@docs last, init, getAt, (!!), uncons, maximumBy, minimumBy, andMap, andThen, reverseMap, takeWhile, dropWhile, unique, uniqueBy, allDifferent, allDifferentBy, replaceIf, setAt, remove, updateIf, updateAt, updateIfIndex, removeAt, removeIfIndex, filterNot, swapAt, stableSortWith
@docs last, init, getAt, (!!), uncons, maximumBy, minimumBy, andMap, andThen, reverseMap, takeWhile, dropWhile, unique, uniqueBy, allDifferent, allDifferentBy, replaceIf, setAt, remove, updateIf, updateAt, updateIfIndex, removeAt, removeIfIndex, removeSubsequentDuplicates, filterNot, swapAt, stableSortWith


# List transformations
Expand Down Expand Up @@ -686,6 +687,19 @@ remove x xs =
y :: remove x ys


{-| Remove Adjacent Duplicates.

removeSubsequentDuplicates [ 1, 2, 2, 3, 2, 3, 3, 3, 1 ] == [ 1, 2, 3, 2, 3, 1 ]

-}
removeSubsequentDuplicates : List a -> List a
removeSubsequentDuplicates items =
List.Extra.group items
|> List.map (\x -> List.take 1 x)
|> List.concat



{-| Set a value in a list by index. Return the original list if the index is out of range.

setAt 0 42 [ 1, 2, 3 ] == [ 42, 2, 3 ]
Expand Down