| Copyright | (c) Leon Vatthauer 2026 |
|---|---|
| License | GPL-3 |
| Maintainer | Leon Vatthauer <leon.vatthauer@fau.de> |
| Stability | experimental |
| Portability | non-portable (ghc-wasm-meta) |
| Safe Haskell | None |
| Language | GHC2024 |
Util
Description
Some utility functions.
Synopsis
- allCombinations :: [NonEmpty a] -> NonEmpty [a]
- interleave :: [a] -> [a] -> [a]
- insertAt :: a -> Int -> [a] -> Maybe [a]
- removeAt :: Int -> [a] -> Maybe [a]
- updateAtM :: MonadFail m => Int -> (a -> m a) -> [a] -> m [a]
- (%=?) :: MonadState record m => Lens record field -> (field -> Maybe field) -> m ()
- inRange :: (Int, Int) -> Int -> Bool
List utilities
allCombinations :: [NonEmpty a] -> NonEmpty [a] Source #
Returns all combinations of a list of list.
Taken from package
liquid-fixpoint
and adjusted to use NonEmpty.
Satisfies:
allCombinations :: xss:[[a]] -> [{v:[a]| len v == len xss}]
interleave :: [a] -> [a] -> [a] Source #
Interleaves two lists, taking elements alternately from each. The result ends when the first list is exhausted. If the second list runs out first, the remaining head of the first list is appended.
>>>interleave [1,2,3] [10,20,30][1,10,2,20,3,30]>>>interleave [1,2,3] [10][1,10,2]
updateAtM :: MonadFail m => Int -> (a -> m a) -> [a] -> m [a] Source #
Update nth element of a list, if it exists.
O(min index n).
Precondition: the index is >= 0. (Copied from Agda.Utils.List and adjusted for monadicity)