Hoogle Search
Within LTS Haskell 24.4 (ghc-9.10.2)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
sortBy :: (PrimMonad m, MVector v e) => Int -> Int -> (Int -> e -> Int) -> v (PrimState m) e -> m ()vector-algorithms Data.Vector.Algorithms.Radix Radix sorts an array using custom radix information requires the number of passes to fully sort the array, the size of of auxiliary arrays necessary (should be one greater than the maximum value returned by the radix function), and a radix function, which takes the pass and an element, and returns the relevant radix.
sortBy :: (PrimMonad m, MVector v e) => Comparison e -> v (PrimState m) e -> m ()vector-algorithms Data.Vector.Algorithms.Tim Sorts an array using a custom comparison.
sortUniq :: (PrimMonad m, MVector v e, Ord e) => v (PrimState m) e -> m (v (PrimState m) e)vector-algorithms Data.Vector.Algorithms.Tim A variant on sort that returns a vector of unique elements.
-
vector-algorithms Data.Vector.Algorithms.Tim A variant on sortBy which returns a vector of unique elements.
sortIndex :: (Ord t, Element t) => Vector t -> Vector Ihmatrix Numeric.LinearAlgebra.Data >>> m <- randn 4 10 >>> disp 2 m 4x10 -0.31 0.41 0.43 -0.19 -0.17 -0.23 -0.17 -1.04 -0.07 -1.24 0.26 0.19 0.14 0.83 -1.54 -0.09 0.37 -0.63 0.71 -0.50 -0.11 -0.10 -1.29 -1.40 -1.04 -0.89 -0.68 0.35 -1.46 1.86 1.04 -0.29 0.19 -0.75 -2.20 -0.01 1.06 0.11 -2.09 -1.58
>>> disp 2 $ m ?? (All, Pos $ sortIndex (m!1)) 4x10 -0.17 -1.04 -1.24 -0.23 0.43 0.41 -0.31 -0.17 -0.07 -0.19 -1.54 -0.63 -0.50 -0.09 0.14 0.19 0.26 0.37 0.71 0.83 -1.04 0.35 1.86 -0.89 -1.29 -0.10 -0.11 -0.68 -1.46 -1.40 -2.20 0.11 -1.58 -0.01 0.19 -0.29 1.04 1.06 -2.09 -0.75
sortVector :: (Ord t, Element t) => Vector t -> Vector thmatrix Numeric.LinearAlgebra.Data No documentation available.
sortBy :: SemiSequence seq => (Element seq -> Element seq -> Ordering) -> seq -> seqmono-traversable Data.Sequences Sort a sequence using an supplied element ordering function.
> let compare' x y = case compare x y of LT -> GT; EQ -> EQ; GT -> LT > sortBy compare' [5,3,6,1,2,4] [6,5,4,3,2,1]
sortOn :: (Ord o, SemiSequence seq) => (Element seq -> o) -> seq -> seqmono-traversable Data.Sequences Same as sortBy . comparing. Since 0.7.0
sortBy :: (a -> a -> Ordering) -> [a] -> [a]rio RIO.List The sortBy function is the non-overloaded version of sort. The argument must be finite. The supplied comparison relation is supposed to be reflexive and antisymmetric, otherwise, e. g., for _ _ -> GT, the ordered list simply does not exist. The relation is also expected to be transitive: if it is not then sortBy might fail to find an ordered permutation, even if it exists.
Examples
>>> sortBy (\(a,_) (b,_) -> compare a b) [(2, "world"), (4, "!"), (1, "Hello")] [(1,"Hello"),(2,"world"),(4,"!")]
sortOn :: Ord b => (a -> b) -> [a] -> [a]rio RIO.List Sort a list by comparing the results of a key function applied to each element. sortOn f is equivalent to sortBy (comparing f), but has the performance advantage of only evaluating f once for each element in the input list. This is called the decorate-sort-undecorate paradigm, or Schwartzian transform. Elements are arranged from lowest to highest, keeping duplicates in the order they appeared in the input. The argument must be finite.
Examples
>>> sortOn fst [(2, "world"), (4, "!"), (1, "Hello")] [(1,"Hello"),(2,"world"),(4,"!")]
>>> sortOn length ["jim", "creed", "pam", "michael", "dwight", "kevin"] ["jim","pam","creed","kevin","dwight","michael"]
Performance notes
This function minimises the projections performed, by materialising the projections in an intermediate list. For trivial projections, you should prefer using sortBy with comparing, for example:>>> sortBy (comparing fst) [(3, 1), (2, 2), (1, 3)] [(1,3),(2,2),(3,1)]
Or, for the exact same API as sortOn, you can use `sortBy . comparing`:>>> (sortBy . comparing) fst [(3, 1), (2, 2), (1, 3)] [(1,3),(2,2),(3,1)]