[Haskell-beginners] Using findIndex and then splitAt in Data.List

Francesco Ariis fa-ml at ariis.it
Fri Feb 27 22:18:47 UTC 2015


On Fri, Feb 27, 2015 at 04:51:46PM -0500, David McBride wrote:
> Another way you can deal with this is using the maybe function.
> If you are absolutely positive that it can never fail, it doesn't
> hurt to choose a default index of 0.
>
> let gradeItemIndex = ...
> let twoListsTuple = splitAt (maybe 0 id gradeItemIndex)

And if you don't trust your gut feelings, instead of `maybe 0...` place

    maybe (error "tlt") id gradeItemIndex

as some kind of crude assertion.



More information about the Beginners mailing list