<commit_before>"use strict";

import from from "../src/eslinq";
import { Sequence } from "../src/eslinq";
import { even } from "./helpers";

describe(".first", () => {

	it("throws an error if called on an empty sequence", () => {
		const bomb = () => Sequence.empty().first();
		expect(bomb).toThrowError("No matching element found");
	});
	
	it("throws an error if `matches` is not a function", () => {
		const bomb = () => from([1]).first(1);
		expect(bomb).toThrowError("`matches` should be a function");
	});
	
	it("returns the element if called on a single-element sequence without a condition", () => {
		expect(from([2]).first()).toBe(2);
	});
	
	it("returns the element if called on a single-element sequence with a matching condition", () => {
		expect(from([2]).first(even)).toBe(2);
	});
	
	it("throws an error if the single element of a sequence does not match", () => {
		const bomb = () => from([1]).first(n => n === 2);
		expect(bomb).toThrowError("No matching element found");
	});
	
	it("returns the first element if called without a condition", () => {
		expect(from([3, 4]).first()).toBe(3);
	});<commit_msg>Add another test case for `first`<commit_after>"use strict";

import from from "../src/eslinq";
import { Sequence } from "../src/eslinq";
import { even } from "./helpers";

describe(".first", () => {

	it("throws an error if called on an empty sequence", () => {
		const bomb = () => Sequence.empty().first();
		expect(bomb).toThrowError("No matching element found");
	});
	
	it("throws an error if called on an empty sequence with a constant true condition", () => {
		const bomb = () => Sequence.empty().first(_ => true);
		expect(bomb).toThrowError("No matching element found");
	});
	
	it("throws an error if `matches` is not a function", () => {
		const bomb = () => from([1]).first(1);
		expect(bomb).toThrowError("`matches` should be a function");
	});
	
	it("returns the element if called on a single-element sequence without a condition", () => {
		expect(from([2]).first()).toBe(2);
	});
	
	it("returns the element if called on a single-element sequence with a matching condition", () => {
		expect(from([2]).first(even)).toBe(2);
	});
	
	it("throws an error if the single element of a sequence does not match", () => {
		const bomb = () => from([1]).first(n => n === 2);
		expect(bomb).toThrowError("No matching element found");
	});
	
	it("returns the first element if called without a condition", () => {
		expect(from([3, 4]).first()).toBe(3);
	});
{'fraction_non_alphanumeric': 0.19437751004016066, 'fraction_numerical': 0.008835341365461847, 'mean_word_length': 4.157349896480331, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 28, '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': '1259527', 'n_tokens_mistral': 790, 'n_tokens_neox': 736, 'n_words': 243}