8000 Adds List.push and prepend by gampleman · Pull Request #70 · elmcraft/core-extra · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Adds List.push and prepend #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs.json

Large diffs are not rendered by default.

43 changes: 41 additions & 2 deletions src/List/Extra.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module List.Extra exposing
( last, init, getAt, cons, uncons, unconsLast, maximumBy, maximumWith, minimumBy, minimumWith, andMap, andThen, reverseMap, takeWhile, dropWhile, unique, uniqueBy, allDifferent, allDifferentBy, setIf, setAt, remove, updateIf, updateAt, updateIfIndex, removeAt, removeIfIndex, removeWhen, swapAt, stableSortWith
( last, init, getAt, cons, uncons, unconsLast, push, appendTo, prependTo, maximumBy, maximumWith, minimumBy, minimumWith, andMap, andThen, reverseMap, takeWhile, dropWhile, unique, uniqueBy, allDifferent, allDifferentBy, setIf, setAt, remove, updateIf, updateAt, updateIfIndex, removeAt, removeIfIndex, removeWhen, swapAt, stableSortWith
, intercalate, transpose, subsequences, permutations, interweave, cartesianProduct, uniquePairs
, foldl1, foldr1, indexedFoldl, indexedFoldr, Step(..), stoppableFoldl
, scanl, scanl1, scanr, scanr1, mapAccuml, mapAccumr, unfoldr, iterate, initialize, cycle, reverseRange
Expand All @@ -17,7 +17,7 @@ module List.Extra exposing

# Basics

@docs last, init, getAt, cons, uncons, unconsLast, maximumBy, maximumWith, minimumBy, minimumWith, andMap, andThen, reverseMap, takeWhile, dropWhile, unique, uniqueBy, allDifferent, allDifferentBy, setIf, setAt, remove, updateIf, updateAt, updateIfIndex, removeAt, removeIfIndex, removeWhen, swapAt, stableSortWith
@docs last, init, getAt, cons, uncons, unconsLast, push, appendTo, prependTo, maximumBy, maximumWith, minimumBy, minimumWith, andMap, andThen, reverseMap, takeWhile, dropWhile, unique, uniqueBy, allDifferent, allDifferentBy, setIf, setAt, remove, updateIf, updateAt, updateIfIndex, removeAt, removeIfIndex, removeWhen, swapAt, stableSortWith


# List transformations
Expand Down Expand Up @@ -303,6 +303,45 @@ unconsLast list =
|> Just


{-| Adds an element to the end of a list. Not terribly efficient, but comes up a lot in UI programming:

someItems
|> List.map viewItem
|> List.Extra.push addNewItemButton
|> Html.ul []

-}
push : a -> List a -> List a
push x xs =
xs ++ [ x ]


{-| Append with arguments optimised for pipelines.

[ 4, 5, 6 ]
|> List.Extra.appendTo [ 1, 2, 3 ]
--> [ 4, 5, 6, 1, 2, 3 ]

Useful for pipelined code, where the argument order of `List.append` doesn't quite work.

-}
appendTo : List a -> List a -> List a
appendTo a b =
List.append b a


{-| Prepends a list.

[ 4, 5, 6 ]
|> List.Extra.prependTo [ 1, 2, 3 ]
--> [ 1, 2, 3, 4, 5, 6 ]

-}
prependTo : List a -> List a -> List a
prependTo =
List.append


{-| Find the first maximum element in a list using a comparable transformation
-}
maximumBy : (a -> comparable) -> List a -> Maybe a
Expand Down
1 change: 0 additions & 1 deletion tests/elm-verify-examples.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"root": "../src",
"tests": [
"Array.Extra",
"Basics.Extra",
Expand Down
0