function iterUntilEach( iterator, predicate, fcn, thisArg ) {
	var iter;
	var FLG;
	var i;
	if ( !isIteratorLike( iterator ) ) {
		throw new TypeError( format( 'invalid argument. First argument must be an iterator protocol-compliant object. Value: `%s`.', iterator ) );
	}
	if ( !isFunction( predicate ) ) {
		throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', predicate ) );
	}
	if ( !isFunction( fcn ) ) {
		throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', fcn ) );
	}
	i = -1;

	// Create an iterator protocol-compliant object:
	iter = {};
	setReadOnly( iter, 'next', next );
	setReadOnly( iter, 'return', end );

	// If an environment supports `Symbol.iterator`, make the iterator iterable:
	if ( iteratorSymbol && isFunction( iterator[ iteratorSymbol ] ) ) {
		setReadOnly( iter, iteratorSymbol, factory );
	}
	return iter;

	/**
	* Returns an iterator protocol-compliant object containing the next iterated value.
	*
	* @private
	* @returns {Object} iterator protocol-compliant object
	*/
	function next() {
		var v;
		i += 1;
		if ( FLG ) {
			return {
				'done': true
			};
		}
		v = iterator.next();
		if ( v.done ) {
			FLG = true;
			return v;
		}
		v = v.value;
		if ( predicate( v, i ) === true ) {
			FLG = true;
			return {
				'done': true
			};
		}
		fcn.call( thisArg, v, i );
		return {
			'value': v,
			'done': false
		};
	}

	/**
	* Finishes an iterator.
	*
	* @private
	* @param {*} [value] - value to return
	* @returns {Object} iterator protocol-compliant object
	*/
	function end( value ) {
		FLG = true;
		if ( arguments.length ) {
			return {
				'value': value,
				'done': true
			};
		}
		return {
			'done': true
		};
	}

	/**
	* Returns a new iterator.
	*
	* @private
	* @returns {Iterator} iterator
	*/
	function factory() {
		return iterUntilEach( iterator[ iteratorSymbol ](), predicate, fcn, thisArg ); // eslint-disable-line max-len
	}
}
Returns an iterator which invokes a function for each iterated value before returning the iterated value until either a predicate function returns `true` or the iterator has iterated over all values.

@param {Iterator} iterator - input iterator
@param {Function} predicate - function which indicates whether to continue iterating
@param {Function} fcn - function to invoke
@param {*} [thisArg] - execution context
@throws {TypeError} first argument must be an iterator protocol-compliant object
@throws {TypeError} second argument must be a function
@throws {TypeError} third argument must be a function
@returns {Iterator} iterator

@example
var array2iterator = require( '@stdlib/array/to-iterator' );
var iterUntilEach = require( '@stdlib/iter/until-each' );

function predicate( v ) {
    return v > 2;
}

function assert( v ) {
    if ( v !== v ) {
        throw new Error( 'should not be NaN' );
    }
}

var it = iterUntilEach( array2iterator( [ 1, 2, 3, 4 ] ), predicate, assert );
// returns {}

var r = it.next().value;
// returns 1

r = it.next().value;
// returns 2

r = it.next().value;
// undefined

// ...