<commit_before>/**    / \____  _    ______   _____ / \____   ____  _____
 *    /  \__  \/ \  / \__  \ /  __//  \__  \ /    \/ __  \   Javaslang
 *  _/  // _\  \  \/  / _\  \\_  \/  // _\  \  /\  \__/  /   Copyright 2014 <NAME>
 * /___/ \_____/\____/\_____/____/\___\_____/_/  \_/____/    Licensed under the Apache License, Version 2.0
 */
package javaslang.match;

import static javaslang.Lang.requireNonNull;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.DoubleFunction;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.LongFunction;
import java.util.function.Supplier;

import javaslang.Lambdas;
import javaslang.exception.NonFatal;
import javaslang.option.None;
import javaslang.option.Option;
import javaslang.option.Some;

/**
 * A better switch for Java. A Match...
 * <ul>
 * <li>is lazy</li>
 * <li>is an expression, i.e. a {@code Function<Object, R>}</li>
 * <li>is able to match types, i.e. {@code Matchs.caze((byte b) -> "a byte: " + b)}</li>
 * <li>is able to match values, i.e. {@code Matchs.caze(BigDecimal.ZERO, b -> "Zero: " + b)}</li>
 * </ul>
 * 
 * Example of a Match as <strong>partial</strong> function:
 * 
 * <pre>
 * <code>final Match&lt;Number&gt; toNumber = new Match.Builder&lt;Number&gt;()
 *     .caze((Integer i) -&gt; i)
 *     .caze((String s) -&gt; new BigDecimal(s))
 *     .build();
 * final Number number = toNumber.apply(1.0d); // throws a MatchError</code>
 * </pre>
 * 
 * Example of a Match as <strong>total</strong> function:
 * 
 * <pre>
 * <code>final Match&lt;Number&gt; toNumber = new Match.Builder&lt;Number&gt;()
 *     .caze((Integer i) -&gt; i)
 *     .caze((String s) -&gt; new BigDecimal(s))
 *     .orElse(() -&gt; -1)
 *     .build();
 * final Number number = toNumber.apply(1.0d); // result: -1</code>
 * </pre>
 * 
 * The following calls are equivalent:
 * <ul>
 * <li>{@code new Match.Builder<R>.caze(...).build().apply(obj)}</li>
 * <li>{@code new Match.Builder<R>.caze(...).apply(obj)}</li>
 * <li>{@code Matchs.caze(...).apply(obj)}</li>
 * </ul>
 * 
 * @param <R> The result type of the Match expression.
 * 
 * @see javaslang.match.Matchs
 */
public class Match<R> implements Function<Object, R> {

	private final List<Case<R>> cases;
	private final Option<Supplier<R>> defaultOption;

	private Match(List<Case<R>> cases, Option<Supplier<R>> defaultOption) {
		this.cases = cases;
		this.defaultOption = defaultOption;
	}

	/**<commit_msg>minor change to javadoc<commit_after>/**    / \____  _    ______   _____ / \____   ____  _____
 *    /  \__  \/ \  / \__  \ /  __//  \__  \ /    \/ __  \   Javaslang
 *  _/  // _\  \  \/  / _\  \\_  \/  // _\  \  /\  \__/  /   Copyright 2014 <NAME>
 * /___/ \_____/\____/\_____/____/\___\_____/_/  \_/____/    Licensed under the Apache License, Version 2.0
 */
package javaslang.match;

import static javaslang.Lang.requireNonNull;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.DoubleFunction;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.function.LongFunction;
import java.util.function.Supplier;

import javaslang.Lambdas;
import javaslang.exception.NonFatal;
import javaslang.option.None;
import javaslang.option.Option;
import javaslang.option.Some;

/**
 * A better switch for Java. A Match...
 * <ul>
 * <li>is lazy</li>
 * <li>is an expression, i.e. a {@code Function<Object, R>}</li>
 * <li>is able to match types, i.e. {@code Matchs.caze((byte b) -> "a byte: " + b)}</li>
 * <li>is able to match values, i.e. {@code Matchs.caze(BigDecimal.ZERO, b -> "Zero: " + b)}</li>
 * </ul>
 * 
 * Example of a Match as <strong>partial</strong> function:
 * 
 * <pre>
 * <code>final Match&lt;Number&gt; toNumber = new Match.Builder&lt;Number&gt;()
 *     .caze((Integer i) -&gt; i)
 *     .caze((String s) -&gt; new BigDecimal(s))
 *     .build();
 * final Number number = toNumber.apply(1.0d); // throws a MatchError</code>
 * </pre>
 * 
 * Example of a Match as <strong>total</strong> function:
 * 
 * <pre>
 * <code>final Match&lt;Number&gt; toNumber = new Match.Builder&lt;Number&gt;()
 *     .caze((Integer i) -&gt; i)
 *     .caze((String s) -&gt; new BigDecimal(s))
 *     .orElse(() -&gt; -1)
 *     .build();
 * final Number number = toNumber.apply(1.0d); // result: -1</code>
 * </pre>
 * <p>
 * The following calls are equivalent:
 * <ul>
 * <li>{@code new Match.Builder<R>.caze(...).build().apply(obj)}</li>
 * <li>{@code new Match.Builder<R>.caze(...).apply(obj)}</li>
 * <li>{@code Matchs.caze(...).apply(obj)}</li>
 * </ul>
 * 
 * @param <R> The result type of the Match expression.
 * 
 * @see javaslang.match.Matchs
 */
public class Match<R> implements Function<Object, R> {

	private final List<Case<R>> cases;
	private final Option<Supplier<R>> defaultOption;

	private Match(List<Case<R>> cases, Option<Supplier<R>> defaultOption) {
		this.cases = cases;
		this.defaultOption = defaultOption;
	}

	/**
{'fraction_non_alphanumeric': 0.18932327842825958, 'fraction_numerical': 0.004762849771780115, 'mean_word_length': 3.064516129032258, 'pattern_counts': {'":': 0, '<': 94, '<?xml version=': 0, '>': 98, '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': '2752985', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1849, 'n_words': 400}