3 var callable = require('es5-ext/object/valid-callable')
4 , isString = require('es5-ext/string/is-string')
5 , get = require('./get')
7 , isArray = Array.isArray, call = Function.prototype.call;
9 module.exports = function (iterable, cb/*, thisArg*/) {
10 var mode, thisArg = arguments[2], result, doBreak, broken, i, l, char, code;
11 if (isArray(iterable)) mode = 'array';
12 else if (isString(iterable)) mode = 'string';
13 else iterable = get(iterable);
16 doBreak = function () { broken = true; };
17 if (mode === 'array') {
18 iterable.some(function (value) {
19 call.call(cb, thisArg, value, doBreak);
20 if (broken) return true;
24 if (mode === 'string') {
26 for (i = 0; i < l; ++i) {
29 code = char.charCodeAt(0);
30 if ((code >= 0xD800) && (code <= 0xDBFF)) char += iterable[++i];
32 call.call(cb, thisArg, char, doBreak);
37 result = iterable.next();
39 while (!result.done) {
40 call.call(cb, thisArg, result.value, doBreak);
42 result = iterable.next();