ababup1192
4/30/2017 - 8:40 AM

listZipper.elm

import Html exposing (..)
import Debug

main = let
           xs = [1, 2, 3, 4]
           zippers = [
               goForward (xs, []),
               goForward ([2, 3, 4], [1]),
               goForward ([3, 4], [2, 1]),
               goBack ([4], [3, 2, 1])
               ]
           zippersLi = zippers |> List.map toString |> List.map (\s -> li [] [ text s ] )
       in
          ul [] zippersLi

type alias ListZipper a = (List a, List a)

goForward : ListZipper a -> ListZipper a
goForward (list, bs) =
    case list of
        (x::xs) -> (xs, x::bs)
        _       -> Debug.crash "Can't move forward"

goBack : ListZipper a -> ListZipper a
goBack (xs, bs) =
    case bs of
        (b::bss) -> (b::xs, bss)
        _        -> Debug.crash "Can't move back"