You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					30 lines
				
				542 B
			
		
		
			
		
	
	
					30 lines
				
				542 B
			| 
								 
											3 years ago
										 
									 | 
							
								/* eslint no-constant-condition: 0 */
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * Obliterator Consume Function
							 | 
						||
| 
								 | 
							
								 * =============================
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * Function consuming the given iterator for n or every steps.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * Consume.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @param  {Iterator} iterator - Target iterator.
							 | 
						||
| 
								 | 
							
								 * @param  {number}   [steps]  - Optional steps.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								module.exports = function consume(iterator, steps) {
							 | 
						||
| 
								 | 
							
								  var step,
							 | 
						||
| 
								 | 
							
								    l = arguments.length > 1 ? steps : Infinity,
							 | 
						||
| 
								 | 
							
								    i = 0;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  while (true) {
							 | 
						||
| 
								 | 
							
								    if (i === l) return;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    step = iterator.next();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    if (step.done) return;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    i++;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								};
							 |