diff options
Diffstat (limited to 'stdlib/source/lux/data/coll/stack.lux')
-rw-r--r-- | stdlib/source/lux/data/coll/stack.lux | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/stdlib/source/lux/data/coll/stack.lux b/stdlib/source/lux/data/coll/stack.lux new file mode 100644 index 000000000..05364b832 --- /dev/null +++ b/stdlib/source/lux/data/coll/stack.lux @@ -0,0 +1,47 @@ +## Copyright (c) Eduardo Julian. All rights reserved. +## This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +## If a copy of the MPL was not distributed with this file, +## You can obtain one at http://mozilla.org/MPL/2.0/. + +(;module: + lux + (lux (data (coll [list])))) + +## [Types] +(type: #export (Stack a) + (List a)) + +## [Values] +(def: #export empty + Stack + (list)) + +(def: #export (size stack) + (All [a] (-> (Stack a) Nat)) + (list;size stack)) + +(def: #export (empty? stack) + (All [a] (-> (Stack a) Bool)) + (list;empty? stack)) + +(def: #export (peek stack) + (All [a] (-> (Stack a) (Maybe a))) + (case stack + #;Nil + #;None + + (#;Cons value _) + (#;Some value))) + +(def: #export (pop stack) + (All [a] (-> (Stack a) (Stack a))) + (case stack + #;Nil + #;Nil + + (#;Cons _ stack') + stack')) + +(def: #export (push value stack) + (All [a] (-> a (Stack a) (Stack a))) + (#;Cons value stack)) |