<commit_before>import { Handler, Response, HandlerFunction, isHandlerFunction, isHandler } from './Handler';
import { ServerResponse, IncomingMessage } from 'http';
import Functional from './Functional';

/**
 * Directives are used for processing the middleware stack. Their behavior is as follows:
 *
 * void: continue processing the next element as normal
 * skip: skip the remaining middleware in the current group
 * immediate: immediately return the response and skip the rest of the middleware
 */
export type Directive = Response | 'skip' | 'immediate';

export default class Group implements Handler {
	readonly handlers: Handler[];

	constructor(handlers: Array<Handler | HandlerFunction> = []) {
		this.handlers = [];

		for (let handler of handlers) {
			this.add(handler);
		}
	}

	add(handler: Handler | HandlerFunction): this {
		if (isHandlerFunction(handler)) {
			this.handlers.push(new Functional(handler));
		}
		else if (isHandler(handler)) {
			this.handlers.push(handler);<commit_msg>allow list of handlers to be added to a group<commit_after>import { Handler, Response, HandlerFunction, isHandlerFunction, isHandler } from './Handler';
import { ServerResponse, IncomingMessage } from 'http';
import Functional from './Functional';

/**
 * Directives are used for processing the middleware stack. Their behavior is as follows:
 *
 * void: continue processing the next element as normal
 * skip: skip the remaining middleware in the current group
 * immediate: immediately return the response and skip the rest of the middleware
 */
export type Directive = Response | 'skip' | 'immediate';

export type HandlerDefinition = Handler | HandlerFunction | Array<Handler | HandlerFunction>;

export default class Group implements Handler {
	readonly handlers: Handler[];

	constructor(handlers: HandlerDefinition = []) {
		this.handlers = [];
		this.add(handlers);
	}

	add(handler: HandlerDefinition): this {
		if (Array.isArray(handler)) {
			handler.forEach(this.add.bind(this));
		}
		else if (isHandlerFunction(handler)) {
			this.handlers.push(new Functional(handler));
		}
		else if (isHandler(handler)) {
			this.handlers.push(handler);
{'fraction_non_alphanumeric': 0.1046780917091246, 'fraction_numerical': 0.0, 'mean_word_length': 4.869565217391305, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6472988', 'n_tokens_mistral': 618, 'n_tokens_neox': 563, 'n_words': 204}