diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-16 23:57:50 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-16 23:57:50 -0500 |
| commit | 8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 (patch) | |
| tree | 13e5b2878f19ee24272ead8a92a9cb84b33ad0e5 /bash/types.sh | |
| parent | a05f7822b10ed4cdd61ed8384299a003baf1c1c6 (diff) | |
| download | mal-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.sh | 29 |
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) |
