Skip to content

Instantly share code, notes, and snippets.

@ToJans
Last active August 29, 2015 14:13
Show Gist options
  • Save ToJans/5f1b1743dadcdf3b6e7c to your computer and use it in GitHub Desktop.
Save ToJans/5f1b1743dadcdf3b6e7c to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var ints = new int[] { 1, 2, 3 };
var strings = new string[] { "alice", "bob", "charlie" };
MyList.methods<int>()[0](ints);
MyList.methods<string>()[0](strings);
}
public class MyList
{
//[tail,init,reverse,tail] :: [ [a]->[a] ]
public static Func<T[], T[]>[] methods<T>()
{
Func<T[], T[]> tail = items => items.Skip(1).ToArray();
Func<T[], T[]> init = items => items.Take(1).ToArray();
Func<T[], T[]> reverse = items => items.Reverse().ToArray();
return new Func<T[], T[]>[] { tail, init, reverse, tail };
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment