You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@Boarders I can see how such function can be useful (especially for Storable, Unbox and Prim, when b doesn't have an instance, while a does), but there is a problem with your suggested implementation. Namely function f will be evaluated 2*n - 1 times and in case when f is really expensive this could be very noticeable.
A possibly better solution would be to first zip with that function over:
minimumOn:: (Ordb, Vectorva) => (a->b) ->va->a
{-# INLINE minimumOn #-}
minimumOn f =fst.Bundle.foldl1' minBy .Bundle.map (\a -> (a, f a)) . stream
where
{-# INLINE minBy #-}
minBy x y =casecompare (snd x) (snd y) ofGT-> y
_ -> x
If anyone is willing to implement this and maximumOn for all vector types with docs, tests and at least one benchmark, I would not be opposed to merging such addition.
Reacted by Callan McGill, ˌbodʲɪˈɡrʲim and Claudi Lleyda Moltó
Activity
lehins commentedon Sep 21, 2020
@Boarders I can see how such function can be useful (especially for
Storable,UnboxandPrim, whenbdoesn't have an instance, whileadoes), but there is a problem with your suggested implementation. Namely functionfwill be evaluated2*n - 1times and in case whenfis really expensive this could be very noticeable.A possibly better solution would be to first zip with that function over:
If anyone is willing to implement this and
maximumOnfor all vector types with docs, tests and at least one benchmark, I would not be opposed to merging such addition.Merge pull request #356 from claudi/331-minimumOn-maximumOn
Shimuuar commentedon Jan 17, 2021
Fixed by #356