<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/arithmetic.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-07-21 19:53:14 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-07-21 19:53:14 +0100
commite832b30f31c56614afe689035af4e04a29e77896 (patch)
tree5f49bc944b9505717541d774f1df3fa537720477 /subex/arithmetic.go
parentbed0e712deda5038f52e495bacae003098df7a55 (diff)
downloadstred-go-e832b30f31c56614afe689035af4e04a29e77896.tar
Adds an incredibly simple equality operator
Diffstat (limited to 'subex/arithmetic.go')
-rw-r--r--subex/arithmetic.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/subex/arithmetic.go b/subex/arithmetic.go
index 9e5e530..4cbc9db 100644
--- a/subex/arithmetic.go
+++ b/subex/arithmetic.go
@@ -156,3 +156,18 @@ func notValues(values walk.ValueList) (notted walk.ValueList, err error) {
}
return notted, nil
}
+
+// Returns true if all values are equal, false if not
+func equalValues(values walk.ValueList) (walk.ValueList, error) {
+ if len(values) == 0 {
+ return walk.ValueList{walk.BoolScalar(true)}, nil
+ }
+ first := values[0]
+ for _, value := range values[1:] {
+ // TODO: Refine the equality check
+ if value != first {
+ return walk.ValueList{walk.BoolScalar(false)}, nil
+ }
+ }
+ return walk.ValueList{walk.BoolScalar(true)}, nil
+}