To answer your question about going from (Maybe a) to a, you need a default value for a, and then you can use Maybe.withDefault. If there is no default value, then there is no type-safe way to go from Maybe a to a.
Here's the code:
maxNum : List ( comparable, number ) -> Maybe ( comparable, number )
maxNum tuples =
case tuples of
x :: xs ->
Just
(List.foldl
(\(( _, count ) as tup) maxSoFar ->
if count + 0 > (snd maxSoFar) then
tup
else
maxSoFar
)
x
xs
)
_ ->
Nothing
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks Joey. This compiles on elm-lang/try even with the + 0 removed, so is there a smaller, reproducible version of this possible bug?Also, you can replace _ with an explicit [] match. And for those watching the thread on <|, this is the perfect place to stick it after Just and removed the parens around foldl.
--
Just is a Constructor for Maybe. Get rid of it and I think you'll be OK.
--
--
Depends on the sort. For a typical implementation of insertion sort in Haskell, the function min list = head (sort list) finds the minimum in O(length of the list).
+1 for maximumBy, but I think even in a lazy language you'd have to run the entire sort before taking the head.
--