using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace BaseTree
{
public static partial class ƒ
{
public static Id<T1> App<T, T1>(this Id<Func<T, T1>> @this, Id<T> fa) => @this.Map(f => f(fa.source));
// public static List<T1> App<T, T1>(this List<Func<T, T1>> @this, List<T> fa) => fa.Select(a=> @this.Select(g =>g(a) )).ToList();
public static async Task<V> SelectMany<T, U, V>(
this Task<T> source, Func<T, Task<U>> selector, Func<T, U, V> resultSelector)
{
T t = await source;
U u = await selector(t);
return resultSelector(t, u);
}
public static async Task<U> Select<T, U>(
this Task<T> source, Func<T, U> selector)
{
T t = await source;
return selector(t);
}
public static async Task<T> Where<T>(
this Task<T> source, Func<T, bool> predicate)
{
T t = await source;
if (!predicate(t)) throw new OperationCanceledException();
return t;
}
}
public interface IMonad<T>
{
IMonad<T1> Bind<T1>(Func<T, IMonad<T1>> bind);
}
public class Id<T> : IMonad<T>
{
public T source;
[Pure]
public Id(T v) => source = v;
public Id<T1> Map<T1>(Func<T, T1> map) => new Id<T1>(map(source));
public IMonad<T1> Bind<T1>(Func<T, IMonad<T1>> bind) => bind(source);
}
public abstract class Tree<T> //: IEnumerable<T>
{
public abstract Tree<T1> Map<T1>(Func<T, T1> f);
public abstract T1 MatchWith<T1>((Func<Leaf<T>, T1> Leaf, Func<Tree<T>, Tree<T>, T1> Node) pattern);
}
public class Node<T> : Tree<T>
{
public override Tree<T1> Map<T1>(Func<T, T1> f)
{
return new Node<T1>(Left.Map(f),...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.