Skip to content

dwayne/elm-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elm-stack

A stack.

An example

import Stack as S

S.isEmpty S.empty == True

S.push 2 (S.push 1 S.empty) == S.fromList [ 2, 1 ]

S.top (S.fromList [ 2, 1 ]) == Just 2

S.pop (S.fromList [ 3, 2, 1 ]) == Just ( 3, S.fromList [ 2, 1 ])

S.toList (S.fromList [ 4, 3, 2, 1 ]) == [ 4, 3, 2, 1 ]

Public API

type Stack a

-- Construct

empty : Stack a
fromList : List a -> Stack a

-- Query

isEmpty : Stack a -> Bool
top : Stack a -> Maybe a

-- Modify

push : a -> Stack a -> Stack a
pop : Stack a -> Maybe ( a, Stack a )

-- Convert

toList : Stack a -> List a