aboutsummaryrefslogtreecommitdiff
path: root/bash/types.sh
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-16 23:57:50 -0500
committerJoel Martin <github@martintribe.org>2014-04-16 23:57:50 -0500
commit8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 (patch)
tree13e5b2878f19ee24272ead8a92a9cb84b33ad0e5 /bash/types.sh
parenta05f7822b10ed4cdd61ed8384299a003baf1c1c6 (diff)
downloadmal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.tar.gz
mal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.zip
All: move some fns to core. Major cleanup.
- Don't import/require core until step4. - Define cond/or macros from step8
Diffstat (limited to 'bash/types.sh')
-rw-r--r--bash/types.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/bash/types.sh b/bash/types.sh
index 8e256be..6781492 100644
--- a/bash/types.sh
+++ b/bash/types.sh
@@ -185,6 +185,11 @@ _hash_map () {
}
_hash_map? () { [[ ${1} =~ ^hmap_ ]]; }
+_contains? () {
+ local obj="${ANON["${1}"]}"
+ eval [[ "\${${obj}[\"${2}\"]+isset}" ]]
+}
+
_copy_hash_map () {
local orig_obj="${ANON["${1}"]}"
_hash_map
@@ -243,6 +248,30 @@ _nth () {
r=${temp[${2}]}
}
+_first () {
+ local temp="${ANON["${1}"]}"
+ r="${temp%% *}"
+ [ "${r}" ] || r="${__nil}"
+}
+
+_last () {
+ local temp="${ANON["${1}"]}"
+ r="${temp##* }"
+}
+
+# Creates a new vector/list of the everything after but the first
+# element
+_rest () {
+ local temp="${ANON["${1}"]}"
+ _list
+ if [[ "${temp#* }" == "${temp}" ]]; then
+ ANON["${r}"]=
+ else
+ ANON["${r}"]="${temp#* }"
+ fi
+}
+
+
_empty? () { [[ -z "${ANON["${1}"]}" ]]; }
# conj that mutates in place (and always appends)