I find myself constantly re-implementing this function:
-- | given a list of indices and a list, return the elements at those indices
-- Assumes indices are sorted. If indices that are out of bounds are given,
-- they are silently ignored.
selectIndices :: [Int] -> [a] -> [a]
selectIndices indices list = go indices list 0
where
go [] _ _ = []
go _ [] _ = []
go (index:indices) (x:xs) currentIndex
| index == currentIndex = x : go indices xs (currentIndex + 1)
| otherwise = go (index:indices) xs (currentIndex + 1)
Would you accept a PR for this?
I find myself constantly re-implementing this function:
Would you accept a PR for this?