00001 var apply = require('./_apply'), 00002 arrayMap = require('./_arrayMap'), 00003 baseIteratee = require('./_baseIteratee'), 00004 baseRest = require('./_baseRest'); 00005 00007 var FUNC_ERROR_TEXT = 'Expected a function'; 00008 00038 function cond(pairs) { 00039 var length = pairs == null ? 0 : pairs.length, 00040 toIteratee = baseIteratee; 00041 00042 pairs = !length ? [] : arrayMap(pairs, function(pair) { 00043 if (typeof pair[1] != 'function') { 00044 throw new TypeError(FUNC_ERROR_TEXT); 00045 } 00046 return [toIteratee(pair[0]), pair[1]]; 00047 }); 00048 00049 return baseRest(function(args) { 00050 var index = -1; 00051 while (++index < length) { 00052 var pair = pairs[index]; 00053 if (apply(pair[0], this, args)) { 00054 return apply(pair[1], this, args); 00055 } 00056 } 00057 }); 00058 } 00059 00060 module.exports = cond;