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

public abstract class DoIf<A> : Functor<A> {

	internal Func<bool> condition = () => false;
	internal Func<bool> guard = () => true;

	public bool truth {
		get {
			return condition() && guard();
		}
	}

	public abstract DoIf<B> MapR<B> (Func<A,B> f);
	public abstract DoIf<A> MapR (Action<A> f);
	public abstract DoIf<A> Do (Func<A> f);
	public abstract DoIf<A> Try ();
	public abstract DoIf<A> If (Func<bool> cond);
	public DoIf<A> If (bool cond) {
		return If (() => cond);
	}
	public abstract DoIf<A> Guard (Func<bool> cond);
	public abstract A value {get;}
	public abstract bool IsWaiting {get;}

	Functor<B> Functor<A>.FMap<B> (Func<A, B> f)
	{
		throw new System.NotImplementedException ();
	}

	public static bool operator true (DoIf<A> m) {
		return !m.IsWaiting;
	}
	
	public static bool operator false (DoIf<A> m) {
		return m.IsWaiting;
	}
	
	public static bool operator ! (DoIf<A> m) {
		return m.IsWaiting;
	}

}

public class Waiting<A> : DoIf<A> {

	Func<A> fa;

	public Waiting () {
		fa = () => {
			throw new ArgumentException("Undefined Action");
			return default(A);
		};
	}

	public Waiting (Func<A> f) {
		fa = f;
	}

	public Waiting (A a) {
		fa = () => a;
	}

	public Waiting (Func<A> f, Func<bool> cond) {
		fa = f;
		condition = cond;
	}

	public Waiting (Func<A> f, Func<bool> cond, Func<bool> guard) {
		fa = f;
		condition = cond;
		this.guard = guard;
	}
	
	public Waiting (A a, Func<bool> cond) {
		fa = () => a;
		condition = cond;
	}

	public override DoIf<A> Do (Func<A> f) {
		this.fa = f;
		return Try ();
	}

	public override DoIf<B> MapR<B> (Func<A, B> f)
	{
		return new Waiting<B> (() => f (fa ()), condition, guard).Try ();
	}

	public override DoIf<A> MapR (Action<A> f)
	{
		return new Waiting<A> (() => f.ToFunc () (fa ()), condition, guard).Try();
	}

	public override DoIf<A> If (Func<bool> cond)
	{
		return new Waiting<A> (fa, () => cond() || condition(), guard).Try();
	}

	public override DoIf<A> Guard (Func<bool> cond)
	{
		return new Waiting<A> (fa, condition, () => cond () && guard ()).Try();
	}

	public override DoIf<A> Try ()
	{
		return truth ? new Done<A>(fa(), condition, guard) as DoIf<A> : this as DoIf<A>;
	}

	public override A value {
		get {
			return default(A);
		}
	}

	public override bool IsWaiting {
		get {
			return true;
		}
	}
}

public class Done<A> : DoIf<A> {

	A a;

	public Done (A val) {
		a = val;
	}

	public Done (A val, Func<bool> cond) {
		a = val;
		condition = cond;
	}

	public Done (A val, Func<bool> cond, Func<bool> guard) {
		a = val;
		condition = cond;
		this.guard = guard;
	}

	public override DoIf<B> MapR<B> (Func<A, B> f)
	{
		return new Waiting<A> (() => a, condition, guard).MapR (f).Try();
	}

	public override DoIf<A> MapR (Action<A> f)
	{
		return MapR (f.ToFunc ());
	}

	public override DoIf<A> Do (Func<A> f) {
		return new Waiting<A> (f, condition).Try();
	}
<commit_msg>MapR -> FMap<commit_after>using UnityEngine;
using System;
using System.Collections;

public abstract class DoIf<A> : Functor<A> {

	internal Func<bool> condition = () => false;
	internal Func<bool> guard = () => true;

	public bool truth {
		get {
			return condition() && guard();
		}
	}

	public abstract DoIf<B> FMap<B> (Func<A,B> f);
	public abstract DoIf<A> FMap (Action<A> f);
	public abstract DoIf<A> Do (Func<A> f);
	public abstract DoIf<A> Try ();
	public abstract DoIf<A> If (Func<bool> cond);
	public DoIf<A> If (bool cond) {
		return If (() => cond);
	}
	public abstract DoIf<A> Guard (Func<bool> cond);
	public abstract A value {get;}
	public abstract bool IsWaiting {get;}

	Functor<B> Functor<A>.FMap<B> (Func<A, B> f)
	{
		throw new System.NotImplementedException ();
	}

	public static bool operator true (DoIf<A> m) {
		return !m.IsWaiting;
	}
	
	public static bool operator false (DoIf<A> m) {
		return m.IsWaiting;
	}
	
	public static bool operator ! (DoIf<A> m) {
		return m.IsWaiting;
	}

}

public class Waiting<A> : DoIf<A> {

	Func<A> fa;

	public Waiting () {
		fa = () => {
			throw new ArgumentException("Undefined Action");
			return default(A);
		};
	}

	public Waiting (Func<A> f) {
		fa = f;
	}

	public Waiting (A a) {
		fa = () => a;
	}

	public Waiting (Func<A> f, Func<bool> cond) {
		fa = f;
		condition = cond;
	}

	public Waiting (Func<A> f, Func<bool> cond, Func<bool> guard) {
		fa = f;
		condition = cond;
		this.guard = guard;
	}
	
	public Waiting (A a, Func<bool> cond) {
		fa = () => a;
		condition = cond;
	}

	public override DoIf<A> Do (Func<A> f) {
		this.fa = f;
		return Try ();
	}

	public override DoIf<B> FMap<B> (Func<A, B> f)
	{
		return new Waiting<B> (() => f (fa ()), condition, guard).Try ();
	}

	public override DoIf<A> FMap (Action<A> f)
	{
		return new Waiting<A> (() => f.ToFunc () (fa ()), condition, guard).Try();
	}

	public override DoIf<A> If (Func<bool> cond)
	{
		return new Waiting<A> (fa, () => cond() || condition(), guard).Try();
	}

	public override DoIf<A> Guard (Func<bool> cond)
	{
		return new Waiting<A> (fa, condition, () => cond () && guard ()).Try();
	}

	public override DoIf<A> Try ()
	{
		return truth ? new Done<A>(fa(), condition, guard) as DoIf<A> : this as DoIf<A>;
	}

	public override A value {
		get {
			return default(A);
		}
	}

	public override bool IsWaiting {
		get {
			return true;
		}
	}
}

public class Done<A> : DoIf<A> {

	A a;

	public Done (A val) {
		a = val;
	}

	public Done (A val, Func<bool> cond) {
		a = val;
		condition = cond;
	}

	public Done (A val, Func<bool> cond, Func<bool> guard) {
		a = val;
		condition = cond;
		this.guard = guard;
	}

	public override DoIf<B> FMap<B> (Func<A, B> f)
	{
		return new Waiting<A> (() => a, condition, guard).FMap (f).Try();
	}

	public override DoIf<A> FMap (Action<A> f)
	{
		return FMap (f.ToFunc ());
	}

	public override DoIf<A> Do (Func<A> f) {
		return new Waiting<A> (f, condition).Try();
	}

{'fraction_non_alphanumeric': 0.17029903699949317, 'fraction_numerical': 0.0, 'mean_word_length': 3.3465491923641704, 'pattern_counts': {'":': 0, '<': 137, '<?xml version=': 0, '>': 160, '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': '6088152', 'n_tokens_mistral': 2503, 'n_tokens_neox': 2334, 'n_words': 673}