Commits

Anonymous committed 0ed5c07

[svn r522] ok

Comments (0)

Files changed (3)

-- Generalise 2 types of of output:	stdout and return code
-
-- folds with return code as accumulator: 
-  $ echo "1 2 3 4" | words | (exit `foldr '\x acc -> (exit $acc) && [ "$x" -gt 2 ] ; echo $?' 0`)
-
-- Add tests for foldr? and foldl?
-
-Prelude> foldl (-) 0 [1,2,3,4]
--10
--- ((((0 - 1) - 2) - 3) - 4)
-
-Prelude> foldr (-) 0 [1,2,3,4]
--2
--- (1 - (2 - (3 - (4 - 0))))
-
+- Add tests for all,any
 }
 
 
+#-- all :: Command1 -> [a] -> Bool
 function all {
 	OPTIND=
 	__check_optr $0 "$@"
 }
 
 
+#-- any :: Command1 -> [a] -> Bool
+function any {
+	OPTIND=
+	__check_optr $0 "$@"
+	shift $(($OPTIND - 1))
+
+	__out=`map -r "$@" | or`
+	if [[ -z "$__rc" ]] ; then
+		echo $__out
+	fi
+
+	return $__out
+}
+
+
 #################################################
 
 
 
 # Thanks to Aaron Kangas for the patch to allow regexp matching
 # under bash < 3.
- _bash_major_version=${BASH_VERSION%%.*}
+_bash_major_version=${BASH_VERSION%%.*}
 _matches(){
 	local result=${1:?}
 	local pattern=${2:?}
 		return 1
 	else
 		if (( _bash_major_version >= 3 )) ; then
-			[[ "$result" =~ "$pattern" ]]
+			eval '[[ "$result" =~ "$pattern" ]]'
 		else
 			echo "$result" | egrep -q "$pattern"
 		fi