<commit_before>using System;
using System.Collections.Generic;

namespace EntitySystem.Utility
{
	public struct Option<T> : IEquatable<Option<T>>
	{
		readonly T _value;
		
		public bool HasValue { get; }
		
		public T Value => Expect(() =>
			new InvalidOperationException($"Option has no value"));
		
		
		public Option(T value, bool hasValue = true)
			{ _value = value; HasValue = hasValue; }
		
		public static Option<T> None { get; } = new Option<T>();
		public static Option<T> Some(T value) => new Option<T>(value);
		
		
		public T Expect(Func<Exception> func)
			{ if (HasValue) return _value; else throw func(); }
		
		public void ExpectNone(Func<Exception> func)
			{ if (HasValue) throw func(); }
		
		
		public T Or(T @default) => (HasValue ? Value : @default);
		
		public T Or(Func<T> func) => (HasValue ? Value : func());
			
		public Option<T> Or(Func<Option<T>> func) => (HasValue ? this : func());
		
		public T OrDefault() => Or(default(T));
		
		
		public Option<TResult> Map<TResult>(Func<T, TResult> func) =>
			(HasValue ? Option<TResult>.Some(func(_value)) : Option<TResult>.None);
		
		public Option<TResult> Map<TResult>(Func<T, Option<TResult>> func) =>
			(HasValue ? func(_value) : Option<TResult>.None);
		
		public Option<TResult> Cast<TResult>() =>
			(HasValue ? (TResult)(object)_value : Option<TResult>.None);
		
		
		public static implicit operator Option<T>(T value)
		{
			if (value == null) throw new ArgumentNullException(
				"Implicit conversion to Option requires value to be non-null");
			return Option<T>.Some(value);
		}
		
		public static explicit operator T(Option<T> option) => option.Value;
		
		
		public override bool Equals(object obj) =>
			((obj is Option<T>) && Equals((Option<T>)obj));
		public bool Equals(Option<T> other) =>
			Equals(other, EqualityComparer<T>.Default);
		public bool Equals(Option<T> other, IEqualityComparer<T> comparer) =>
			((HasValue == other.HasValue) &&
			 (!HasValue || comparer.Equals(_value, other.Value)));
		
		public static bool operator ==(Option<T> left, Option<T> right) => left.Equals(right);
		
		public static bool operator !=(Option<T> left, Option<T> right) => !left.Equals(right);
		
		public override int GetHashCode() =>
			(HasValue ? (_value?.GetHashCode() ?? 0) : 0);
		
		public override string ToString() =>
			$"{ GetType().GetFriendlyName() }.{ Map((value) => $"Some( { value.ToString()} )").Or("None") }";
	}
	
	public static class OptionExtensions
	{
		public static IEnumerable<T> WhereSome<T>(this IEnumerable<Option<T>> source)
		{
			foreach (var option in ThrowIf.Argument.IsNull(source, nameof(source)))
				if (option.HasValue)
					yield return option.Value;
		}
		
		public static IEnumerable<TResult> SelectSome<TSource, TResult>(
			this IEnumerable<TSource> source, Func<TSource, Option<TResult>> selector)
		{
			foreach (var value in ThrowIf.Argument.IsNull(source, nameof(source))) {
				var result = selector(value);
				if (result.HasValue)
					yield return result.Value;
			}
		}
	}<commit_msg>Fix Option<T> to use _value instead of Value<commit_after>using System;
using System.Collections.Generic;

namespace EntitySystem.Utility
{
	public struct Option<T> : IEquatable<Option<T>>
	{
		readonly T _value;
		
		public bool HasValue { get; }
		
		public T Value => Expect(() =>
			new InvalidOperationException($"Option has no value"));
		
		
		public Option(T value, bool hasValue = true)
			{ _value = value; HasValue = hasValue; }
		
		public static Option<T> None { get; } = new Option<T>();
		public static Option<T> Some(T value) => new Option<T>(value);
		
		
		public T Expect(Func<Exception> func)
			{ if (HasValue) return _value; else throw func(); }
		
		public void ExpectNone(Func<Exception> func)
			{ if (HasValue) throw func(); }
		
		
		public T Or(T @default) => (HasValue ? _value : @default);
		
		public T Or(Func<T> func) => (HasValue ? _value : func());
		
		public Option<T> Or(Func<Option<T>> func) => (HasValue ? this : func());
		
		public T OrDefault() => Or(default(T));
		
		
		public Option<TResult> Map<TResult>(Func<T, TResult> func) =>
			(HasValue ? Option<TResult>.Some(func(_value)) : Option<TResult>.None);
		
		public Option<TResult> Map<TResult>(Func<T, Option<TResult>> func) =>
			(HasValue ? func(_value) : Option<TResult>.None);
		
		public Option<TResult> Cast<TResult>() =>
			(HasValue ? (TResult)(object)_value : Option<TResult>.None);
		
		
		public static implicit operator Option<T>(T value)
		{
			if (value == null) throw new ArgumentNullException(
				"Implicit conversion to Option requires value to be non-null");
			return Option<T>.Some(value);
		}
		
		public static explicit operator T(Option<T> option) => option.Value;
		
		
		public override bool Equals(object obj) =>
			((obj is Option<T>) && Equals((Option<T>)obj));
		public bool Equals(Option<T> other) =>
			Equals(other, EqualityComparer<T>.Default);
		public bool Equals(Option<T> other, IEqualityComparer<T> comparer) =>
			((HasValue == other.HasValue) &&
			 (!HasValue || comparer.Equals(_value, other._value)));
		
		public static bool operator ==(Option<T> left, Option<T> right) => left.Equals(right);
		
		public static bool operator !=(Option<T> left, Option<T> right) => !left.Equals(right);
		
		public override int GetHashCode() =>
			(HasValue ? (_value?.GetHashCode() ?? 0) : 0);
		
		public override string ToString() =>
			$"{ GetType().GetFriendlyName() }.{ Map((value) => $"Some( { value.ToString()} )").Or("None") }";
	}
	
	public static class OptionExtensions
	{
		public static IEnumerable<T> WhereSome<T>(this IEnumerable<Option<T>> source)
		{
			foreach (var option in ThrowIf.Argument.IsNull(source, nameof(source)))
				if (option.HasValue)
					yield return option.Value;
		}
		
		public static IEnumerable<TResult> SelectSome<TSource, TResult>(
			this IEnumerable<TSource> source, Func<TSource, Option<TResult>> selector)
		{
			foreach (var value in ThrowIf.Argument.IsNull(source, nameof(source))) {
				var result = selector(value);
				if (result.HasValue)
					yield return result.Value;
			}
		}
	}
{'fraction_non_alphanumeric': 0.14912136639842338, 'fraction_numerical': 0.0006569223189357859, 'mean_word_length': 4.113350125944584, 'pattern_counts': {'":': 0, '<': 100, '<?xml version=': 0, '>': 138, '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': '801463', 'n_tokens_mistral': 2221, 'n_tokens_neox': 1881, 'n_words': 513}