ndmitchell / extra

Extra Haskell functions
Other
94 stars 37 forks source link

firstJust example in docs looks wrong #47

Closed theGhostJW closed 5 years ago

theGhostJW commented 5 years ago

firstJust :: (a -> Maybe b) -> [a] -> Maybe b

Find the first element of a list for which the operation returns Just, along with the result of the operation. Like find but useful where the function also computes some expensive information that can be reused. Particular useful when the function is monadic, see firstJustM.

firstJust id [Nothing,Just 3]  == Just 3
firstJust id [Nothing,Nothing] == Nothing

should it not be ???

firstJust pure [Nothing,Just 3]  == Just 3
firstJust pure [Nothing,Nothing] == Nothing

OR

firstJust Just [Nothing,Just 3]  == Just 3
firstJust Just [Nothing,Nothing] == Nothing
theGhostJW commented 5 years ago

My Bad

ndmitchell commented 5 years ago

I actually test all the documentation so I can be sure it's all correct - too hard otherwise!