Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.List
- reindex :: (Int -> Int) -> [a] -> [a]
- reindex f xs = map fst (sortBy sortFunction elements_indexes_after_f)
- where
- elements_indexes = zip xs [0 .. length xs - 1]
- elements_indexes_after_f = map (\(x, id) -> (x, f id)) elements_indexes
- sortFunction x y
- | snd x < snd y = LT
- | snd x > snd y = GT
- | otherwise = EQ
- -- (Shorter) alternative: sortFunction = \(_, a) (_, b) -> compare a b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement