Copyright | (c) Felpe Santa-Cruz 2021 |
---|---|
License | BSD3 |
Maintainer | fesanmar@gmail.com |
Stability | stable |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module provides functions for relocate an item within a list.
Documentation
up :: Int -> Int -> [a] -> [a] Source #
The up
function moves an element n
positions to
the beginning of a list. If the index provided is out
of range, the list is returned without any modification.
On the other hand, extra steps will be ignored.
Some examples are given below:
>>>
up 2 2 ["one", "two", "three"]
["three", "one", "two"]
>>>
up 4 1 ["one", "two", "three"]
["one", "two", "three"]
>>>
up 2 3 ["one", "two", "three"]
["three", "one", "two"]
down :: Int -> Int -> [a] -> [a] Source #
The down
function moves an element n
positions to
the end of a list. If the index provided is out of range,
the list is returned without any modification. On the other
hand, extra steps will be ignored.
Some examples are given below:
>>>
down 0 1 ["one", "two", "three"]
["two", "one", "three"]
>>>
down 4 1 ["one", "two", "three"]
["one", "two", "three"]
>>>
down 0 4 ["one", "two", "three"]
["two", "three", "one"]
deleteByIndex :: Int -> [a] -> [a] Source #
The deleteByIndex
function removes an element
from a list by its position within it. For example,
>>>
deleteByIndex 1 ["one", "two", "three"]
["one", "three"]
If index is out of range, the list will be returned with no changes. For example:
>>>
deleteByIndex 3 ["one", "two", "three"]
["one", "two", "three"]