elm-community / list-extra

Convenience functions for working with List.

Home Page:http://package.elm-lang.org/packages/elm-community/list-extra/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal for `unconsLast` function

EverybodyKurts opened this issue · comments

It would be defined something like this:

{-| Decompose a list into its last element and the remaining list. If the list is empty, return `Nothing`. Otherwise, return `Just (x, xs)`, where `x` is the last element and `xs` is rest of the list.

    unconsLast [1,2,3] == Just (3, [1,2])
    unconsLast [] = Nothing
-}
unconsLast : List a -> Maybe ( a, List a )
unconsLast =
    List.reverse
        >> uncons
        >> Maybe.andThen (\( lastElem, reversedList ) -> Just ( lastElem, (List.reverse reversedList) ))

I'd be more than happy to create a merge request using the module formatting for documentation and the like. Let me know.

FWIW I believe that in some other communities this is referred to as unsnoc. I think I like your name better though.

Lol. It took me a bit but I get it it. It's clever. I wonder if a beginner to Elm or the List.Extra module would be able to find it easily though.

Do you think I could create a merge request for the unconsLast function following the repo's contribution guidelines?

Yeah, I think it's probably fine to make a PR for this. Wait for @Chadtech to comment if you want a definitive answer though.

Oh shoot. I didnt see this thread, but I did just comment on the PR itself. We can continue this conversation there.

Okay we merged unconsLast in #101 so I am closing this.