Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Testing Yesod applications. (Njagi Mwaniki)
2. Using findIndex and then splitAt in Data.List (Geoffrey Bays)
3. Re: Using findIndex and then splitAt in Data.List (David McBride)
4. Re: Using findIndex and then splitAt in Data.List (Geoffrey Bays)
5. Re: Using findIndex and then splitAt in Data.List (David McBride)
----------------------------------------------------------------------
Message: 1
Date: Fri, 27 Feb 2015 18:35:21 +0300
From: Njagi Mwaniki <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Testing Yesod applications.
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Could I get help with testing yesod applications when it comes to
situations requiring authentication and authorization? Here is my full
question on stack overflow.
http://stackoverflow.com/questions/28764807/performing-authentication-during-testing-browserid
------------------------------
Message: 2
Date: Fri, 27 Feb 2015 15:51:12 -0500
From: Geoffrey Bays <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Using findIndex and then splitAt in
Data.List
Message-ID:
<CAD8ukx7J9usf=TwVnBisMiL0cgXu1+6gyc8R1HYbxo=cett...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi.
An elementary question here about two functions in Data.List:
how to use a value from findIndex which returns a Maybe Int,
and then use that result in splitAt which takes a regular Int?
This is in an IO() do
Like so: (This is in an IO() do block)
let gradeItemIndex = findIndex (\g -> (itemName g) == (itemName
gradeItemP)) gradeItemList
let twoListsTuple = splitAt gradeItemIndex gradeItemList
// does not compile obviously
Many Thanks,
Geoffrey
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150227/cf140870/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 27 Feb 2015 16:16:19 -0500
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using findIndex and then splitAt in
Data.List
Message-ID:
<can+tr43mp6xtbqumotwjgx8eg8+qfrsiyhwdzbkenvduic9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You will probably do a case match on the result of findIndex to find out
whether you want to split there. You will have to deal with the
possibility that the item you are searching for is not in the list.
Untested:
let twoListsTuple = case findIndex (\g -> (itemName g) == (itemName
gradeItemP)) gradeItemList of
Nothing -> (gradeItemList,[])
Just newlists -> newlists
On Fri, Feb 27, 2015 at 3:51 PM, Geoffrey Bays <[email protected]>
wrote:
> Hi.
> An elementary question here about two functions in Data.List:
> how to use a value from findIndex which returns a Maybe Int,
> and then use that result in splitAt which takes a regular Int?
> This is in an IO() do
>
> Like so: (This is in an IO() do block)
>
> let gradeItemIndex = findIndex (\g -> (itemName g) == (itemName
> gradeItemP)) gradeItemList
> let twoListsTuple = splitAt gradeItemIndex gradeItemList
>
> // does not compile obviously
>
> Many Thanks,
>
> Geoffrey
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150227/35fdf469/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 27 Feb 2015 16:41:17 -0500
From: Geoffrey Bays <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using findIndex and then splitAt in
Data.List
Message-ID:
<cad8ukx4dk4+dmbpjnpq17chmt_zcvtyy8p9y8abqqs7oosc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
David:
Thanks for putting me on the right track. This works:
let twoListsTuple = case findIndex (\g -> (itemName g) == (itemName
gradeItemP)) gradeItemList of
Nothing -> (gradeItemList, [])
Just x -> splitAt x gradeItemList
I was not sure if the splitAt function would take a Just Int in place of a
regular Int without complaint, but that seems to be the case.
As it turns out, I can be certain from the context that the item will
definitely be found in the list, but the case statement allows for the
unpacking of the Maybe.
Thanks,
Geoffrey
On Fri, Feb 27, 2015 at 4:16 PM, David McBride <[email protected]> wrote:
> You will probably do a case match on the result of findIndex to find out
> whether you want to split there. You will have to deal with the
> possibility that the item you are searching for is not in the list.
> Untested:
>
> let twoListsTuple = case findIndex (\g -> (itemName g) == (itemName
> gradeItemP)) gradeItemList of
> Nothing -> (gradeItemList,[])
> Just newlists -> newlists
>
> On Fri, Feb 27, 2015 at 3:51 PM, Geoffrey Bays <[email protected]>
> wrote:
>
>> Hi.
>> An elementary question here about two functions in Data.List:
>> how to use a value from findIndex which returns a Maybe Int,
>> and then use that result in splitAt which takes a regular Int?
>> This is in an IO() do
>>
>> Like so: (This is in an IO() do block)
>>
>> let gradeItemIndex = findIndex (\g -> (itemName g) == (itemName
>> gradeItemP)) gradeItemList
>> let twoListsTuple = splitAt gradeItemIndex gradeItemList
>>
>> // does not compile obviously
>>
>> Many Thanks,
>>
>> Geoffrey
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150227/c105e342/attachment-0001.html>
------------------------------
Message: 5
Date: Fri, 27 Feb 2015 16:51:46 -0500
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Using findIndex and then splitAt in
Data.List
Message-ID:
<CAN+Tr42h7SYYZ5SNLO3S86gjmnq1oSC6CgkhPMOB=audr-u...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Ah yeah, I messed up a bit. 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)
However if the code around it changes your assumption may become
invalidated in the future, and your code will explode.
On Fri, Feb 27, 2015 at 4:41 PM, Geoffrey Bays <[email protected]>
wrote:
> David:
> Thanks for putting me on the right track. This works:
>
> let twoListsTuple = case findIndex (\g -> (itemName g) == (itemName
> gradeItemP)) gradeItemList of
> Nothing -> (gradeItemList, [])
> Just x -> splitAt x gradeItemList
>
> I was not sure if the splitAt function would take a Just Int in place of a
> regular Int without complaint, but that seems to be the case.
> As it turns out, I can be certain from the context that the item will
> definitely be found in the list, but the case statement allows for the
> unpacking of the Maybe.
>
> Thanks,
>
> Geoffrey
>
> On Fri, Feb 27, 2015 at 4:16 PM, David McBride <[email protected]> wrote:
>
>> You will probably do a case match on the result of findIndex to find out
>> whether you want to split there. You will have to deal with the
>> possibility that the item you are searching for is not in the list.
>> Untested:
>>
>> let twoListsTuple = case findIndex (\g -> (itemName g) == (itemName
>> gradeItemP)) gradeItemList of
>> Nothing -> (gradeItemList,[])
>> Just newlists -> newlists
>>
>> On Fri, Feb 27, 2015 at 3:51 PM, Geoffrey Bays <[email protected]>
>> wrote:
>>
>>> Hi.
>>> An elementary question here about two functions in Data.List:
>>> how to use a value from findIndex which returns a Maybe Int,
>>> and then use that result in splitAt which takes a regular Int?
>>> This is in an IO() do
>>>
>>> Like so: (This is in an IO() do block)
>>>
>>> let gradeItemIndex = findIndex (\g -> (itemName g) == (itemName
>>> gradeItemP)) gradeItemList
>>> let twoListsTuple = splitAt gradeItemIndex gradeItemList
>>>
>>> // does not compile obviously
>>>
>>> Many Thanks,
>>>
>>> Geoffrey
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150227/82925a3c/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 80, Issue 69
*****************************************