Proposal to generalize the type of List's deleteBy function
Grant Slatton
grantslatton at gmail.com
Sun Jun 21 18:27:00 UTC 2015
When I was talking about this on the IRC channel, I actually mentioned that
I'd prefer (a -> Bool) -> [a] -> [a]. I guess you'd call that filterFirst
or something.
Edward Kmett mentioned on IRC that all the fooBy functions follow
a pattern, which is why deleteBy isn't like that.
On Sunday, June 21, 2015, David Feuer <david.feuer at gmail.com> wrote:
> +1, but what's wrong with just
>
> whatever::(a->Bool)->[a]->[a]
>
> Is this some subtle efficiency thing relating to closure creation?
> On Jun 21, 2015 2:32 AM, "Grant Slatton" <grantslatton at gmail.com
> <javascript:_e(%7B%7D,'cvml','grantslatton at gmail.com');>> wrote:
>
>> Right now the type of deleteBy is:
>>
>> (a -> a -> Bool) -> a -> [a] -> [a]
>>
>> That is, it takes an equality predicate, a value, and a list, and deletes
>> the first element in the list such that the equality predicate returns true
>> for the given value and the element.
>>
>> This can be generalized to:
>>
>> (a -> b -> Bool) -> a -> [b] -> [b]
>>
>>
>> Example use case:
>>
>> keyValues :: [(a, b)]
>>
>> key :: a
>>
>> deleteBy (\x (y, _) -> x == y) key keyValues
>>
>>
>>
>> Thanks
>>
>> Grant Slatton
>>
>> _______________________________________________
>> Libraries mailing list
>> Libraries at haskell.org
>> <javascript:_e(%7B%7D,'cvml','Libraries at haskell.org');>
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20150621/56ec69e5/attachment.html>
More information about the Libraries
mailing list