marshallformula/arrangeable-list/1.1.1

ArrangeableList

This is sort of like a Zip-List data structure - but instead of focusing on a speicific list item - it retains the focuson the same item and moves that item around in the list.

Constructing

initialize : List a -> List a -> a -> ArrangeableList a

Initializes an ArrageableList given a list before (pre), list after (post), and the selected (focused) item.

initialize [] [ "Batman", "Superman", "Green Lantern" ] "Wonder Woman"
fromArray : Array a -> Int -> Maybe (ArrangeableList a)

Create an ArrangeableList from an Array and an integer that specifies an index in the array which should be the selected item. This returns a Maybe Arrageablelist. A Nothing is returned if the index is invalid/out of bounds.

myArray =
    Array.fromList ["Superman", "Batman", "Green Lantern"]


fromArray myArray 1
fromList : List a -> Int -> Maybe (ArrangeableList a)

Create an ArrangeableList from a List and an integer that specifies an index in the list which should be the selected item. This returns a Maybe Arrageablelist. A Nothing is returned if the index is invalid/out of bounds.

fromArray [ "Superman", "Batman", "Green Lantern" ] 0
fromListAtHead : List a -> a -> ArrangeableList a

Creates an ArrangeableList from a supplied List and a value - placing value at the head of the list.

fromListAtHead [ "Superman", "Batman", "Green Lantern" ] "WonderWoman"
fromListAtTail : List a -> a -> ArrangeableList a

Creates and ArrangeableList from a supplied list and a value - placing the value at the tail of the list.

fromListAtHead [ "Superman", "Batman", "Green Lantern" ] "WonderWoman"

Extracting Values

Returns the currently selected value

Returns the items in the list before the selected value.

Returns the items in the list after the selected value.

Uses equality check (==) to check if the given value is the currently selected item in the list

Manipulating the List

Moves the selected item forward in the list.

myList =
    fromListAtHead ["Superman", "Batman", "Green Lantern"] "WonderWoman"


progress myList
    |> toList -- ["Superman", "WonderWoman", "Batman", "Green Lantern"]

Moves the selected item backward in the list.

myList =
    fromListAtTail ["Superman", "Batman", "Green Lantern"] "WonderWoman"


retrogress myList
    |> toList -- ["Superman", "Batman", "WonderWoman", "Green Lantern"]

Transformation

toList : ArrangeableList a -> List a

Returns a regular List of the items that compose the ArrangeableList.

toArray : ArrangeableList a -> Array a

Returns an Array of the items that compose the ArrangeableList.

map : (a -> b) -> ArrangeableList a -> ArrangeableList b

Apply a function to each item of the arrangeable list