<commit_before>﻿using NullGuard;
using System;

namespace FunctionalSharp.OptionTypes
{
    [Serializable]
    public class None<T> : IOption<T>
    {
        public None()
        {
            if (default(T) != null)
            {
                throw new Exception("Option type used for non nullable type " + typeof(T).Name);
            }
        }

        public void IfNotNullDo(Action<T> withValue)
        {

        }

        public void Match(Action<T> withValue, Action withoutValue)
        {
            withoutValue();
        }

        public TResult Match<TResult>(Func<T, TResult> withValue, TResult withoutValue)
        {
            return withoutValue;
        }

        public TResult Match<TResult>(Func<T, TResult> withValue, Func<TResult> withoutValue)
        {
            return withoutValue();
        }

        [return: AllowNull]
        public T ToNullable()
        {
            return default(T);
        }

        public override string ToString()
        {
            return "null value for " + typeof(T).Name;
        }
    }<commit_msg>added xml comments for None.<commit_after>﻿using NullGuard;
using System;

namespace FunctionalSharp.OptionTypes
{
    /// <summary>
    /// A representation for an IOption without a value.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [Serializable]
    public class None<T> : IOption<T>
    {
        /// <summary>
        /// Creates a new None of T. The type T must be nullable, if not an exception will be thrown
        /// </summary>
        public None()
        {
            if (default(T) != null)
            {
                throw new ArgumentOutOfRangeException("Option type used for non nullable type " + typeof(T).Name);
            }
        }

        /// <summary>
        /// Does nothing since None doesnt hold a value.
        /// </summary>
        /// <param name="withValue"></param>
        public void IfNotNullDo(Action<T> withValue)
        {

        }

        /// <summary>
        /// Executes the action <paramref name="withoutValue"/>.
        /// </summary>
        /// <param name="withValue"></param>
        /// <param name="withoutValue"></param>
        public void Match(Action<T> withValue, Action withoutValue)
        {
            withoutValue();
        }

        /// <summary>
        /// returns the value in the parameter withoutValue.
        /// </summary>
        /// <typeparam name="TResult">The result type.</typeparam>
        /// <param name="withValue">Not executed.</param>
        /// <param name="withoutValue">The value returned.</param>
        /// <returns></returns>
        public TResult Match<TResult>(Func<T, TResult> withValue, TResult withoutValue)
        {
            return withoutValue;
        }

        /// <summary>
        /// returns the value generated by running <paramref name="withoutValue"/>.
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="withValue"></param>
        /// <param name="withoutValue"></param>
        /// <returns></returns>
        public TResult Match<TResult>(Func<T, TResult> withValue, Func<TResult> withoutValue)
        {
            return withoutValue();
        }

        /// <summary>
        /// Returns null.
        /// </summary>
        /// <returns></returns>
        [return: AllowNull]
        public T ToNullable()
        {
            return default(T);
        }

        /// <summary>
        /// returns a string "null value for" with the name of the type.
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return "null value for " + typeof(T).Name;
        }
    }
{'fraction_non_alphanumeric': 0.12990855298547607, 'fraction_numerical': 0.0, 'mean_word_length': 1.6282685512367492, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '3827977', 'n_tokens_mistral': 988, 'n_tokens_neox': 965, 'n_words': 260}