From 8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 16 Apr 2014 23:57:50 -0500 Subject: All: move some fns to core. Major cleanup. - Don't import/require core until step4. - Define cond/or macros from step8 --- bash/types.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'bash/types.sh') 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) -- cgit v1.2.3