summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2012-04-10 16:28:11 +0200
committerYorhel <git@yorhel.nl>2012-04-10 16:28:11 +0200
commit9dade183d0678fca6f3ebb3b610859b9b8c482bb (patch)
tree5d8ca3bef57d3f0a0d0b24c06b750ca8c9a67ab6
parent7bdb9d948bf07f56fedd6305ae146de59f51610b (diff)
tuples.go: Added convenient Array() and Map() wrappers
-rw-r--r--tuples.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/tuples.go b/tuples.go
index 4478c5f..2b091ff 100644
--- a/tuples.go
+++ b/tuples.go
@@ -226,11 +226,26 @@ func (t Tuple) Match(p Tuple) bool {
return true
}
-// Same as Tuple{El(a), El(b), ..}
-func Tup(t ...interface{}) Tuple {
- r := make(Tuple, len(t))
+// Same as El(map[string]Element{a: El(b), c: El(d), ...})
+// panics on incorrect arguments
+func Map(t ...interface{}) map[string]Element {
+ r := make(map[string]Element, len(t)/2)
+ for i := 0; i < len(t); i += 2 {
+ r[t[i].(string)] = El(t[i+1])
+ }
+ return r
+}
+
+// Same as []Element{El(a), El(b), ..})
+func Array(t ...interface{}) []Element {
+ r := make([]Element, len(t))
for i, v := range t {
r[i] = El(v)
}
return r
}
+
+// Same as Tuple(Array(a, b, ...))
+func Tup(t ...interface{}) Tuple {
+ return Tuple(Array(t...))
+}