Copyright | (c) Lars Brünjes, 2016 |
---|---|
License | MIT |
Maintainer | brunjlar@gmail.com |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Extensions |
|
This module provides various utilities for working with lists.
- splitLast :: [a] -> Maybe ([a], a)
- pick :: Int -> [a] -> (a, [a])
- distribute :: Int -> [a] -> [[a]]
- pad :: Int -> a -> [a] -> [a]
- data ListEditorT a m b
- editListT :: Monad m => ListEditorT a m () -> [a] -> m [a]
- editT :: Monad m => [a] -> ListEditorT a m ()
- tryLeftT :: Monad m => ListEditorT a m Bool
- tryRightT :: Monad m => ListEditorT a m Bool
- focusT :: Monad m => ListEditorT a m [a]
- type ListEditor a = ListEditorT a Identity
- editList :: ListEditor a () -> [a] -> [a]
- pairs :: [a] -> [(a, a)]
- indexOf :: Eq a => [a] -> a -> Maybe Int
- safeHead :: [a] -> Maybe a
Documentation
splitLast :: [a] -> Maybe ([a], a) Source #
Splits off the last element of a non-empty list.
>>>
splitLast [1, 2, 3]
Just ([1,2],3)
>>>
splitLast []
Nothing
pick :: Int -> [a] -> (a, [a]) Source #
Given a valid index, returns the list element at the index and the remaining elements.
>>>
pick 1 [1,2,3,4]
(2,[1,3,4])
distribute :: Int -> [a] -> [[a]] Source #
Distributes the elements of a list as uniformly as possible amongst a specified number of groups.
>>>
distribute 3 [1,2,3,4,5]
[[3],[4,1],[5,2]]
pad :: Int -> a -> [a] -> [a] Source #
Pads a litst with a provided element on the left.
>>>
pad 4 'x' "oo"
"xxoo"
data ListEditorT a m b Source #
is a monad transformer for editting lists of type ListEditorT
a m[a]
.
Monad m => Monad (ListEditorT a m) Source # | |
Functor m => Functor (ListEditorT a m) Source # | |
Monad m => Applicative (ListEditorT a m) Source # | |
editListT :: Monad m => ListEditorT a m () -> [a] -> m [a] Source #
Runs the editor.
editT :: Monad m => [a] -> ListEditorT a m () Source #
Replaces the list at the "cursor" with the provided list.
focusT :: Monad m => ListEditorT a m [a] Source #
Gets the list under the "cursor".
type ListEditor a = ListEditorT a Identity Source #
Monad for pure list editting.
editList :: ListEditor a () -> [a] -> [a] Source #
Runs the pure editor.
>>>
editList (do _ <- tryRightT; editT [3,2]) [1,2,3]
[1,3,2]
pairs :: [a] -> [(a, a)] Source #
Gets all pairs of adjacent list elements.
>>>
pairs "Haskell"
[('H','a'),('a','s'),('s','k'),('k','e'),('e','l'),('l','l')]