Skip to content

Instantly share code, notes, and snippets.

View ZacharyPatten's full-sized avatar
👊
It's Morphin' Time

ZacharyPatten

👊
It's Morphin' Time
  • Kansas, United States
  • 06:06 (UTC -05:00)
View GitHub Profile
@ZacharyPatten
ZacharyPatten / GenericMathematicalAddition.cs
Last active December 11, 2019 16:18
Generic Mathematics Example Using Runtime Compilation in C#
using System;
using System.Linq.Expressions;
using System.Numerics;
using static Towel.Syntax;
namespace Example
{
public class Program
{
static void Main(string[] args)
@ZacharyPatten
ZacharyPatten / GenericTryParse.cs
Last active October 17, 2019 00:42
Generic TryParse function that works by assuming a static TryParse method exists on the generic type.
using System;
using System.Reflection;
using static Towel.Syntax;
namespace Example
{
class Program
{
static void Main(string[] args)
{
@ZacharyPatten
ZacharyPatten / DelegatesForIteration.cs
Last active October 6, 2019 13:38
This shows an alternative methodology to System.Collections.Generic.IEnumerable<T> that uses delegates for enumeration rather than an enumerator.
using System;
using System.Collections.Generic;
using Towel;
using static Towel.Syntax;
namespace Example
{
class Program
{
static void Main(string[] args)
@ZacharyPatten
ZacharyPatten / GenericEnumUnion.cs
Last active October 17, 2019 00:48
An example of a generic enum union type in C#.
using System;
using System.Linq.Expressions;
using static Towel.Syntax;
namespace Example
{
class Program
{
static void Main(string[] args)
{
@ZacharyPatten
ZacharyPatten / Code Horror New.cs
Last active December 7, 2019 13:10
Code Horror: new
class ոew
{
static void Main()
{
ոew ոew = new ոew();
}
}

Discussion: Static Generic Argument Expressions And Method Constraints

EDIT: I originally thought this would only work with static (non capturing) expressions, but it should work with captures too, so I crosses out "static".

Overview

I think it is possible to allow static expressions and static methods to be used as generic arguments in C#. This would allow for more optimized functional programming without having to wrap functions inside custom struct types. Here is an example:

Overview Code Snippet 1 [click to expand]
@ZacharyPatten
ZacharyPatten / BenchmarkingAbstractionTechniques.md
Last active November 12, 2019 01:15
Benchmarking Abstraction Techniques

Testing Abstraction techniques...

Source Code [click to expand]

using System;
using System.Collections.Generic;
using System.Linq;
@ZacharyPatten
ZacharyPatten / SwitchSyntax.cs
Last active November 21, 2019 11:56
An example of custom Switch syntax in C#. :D
using System;
using static Towel.Syntax;
namespace Example
{
class Program
{
static void Main()
{
// I made custom Switch syntax. :D
@ZacharyPatten
ZacharyPatten / ForSyntax.cs
Last active March 9, 2020 12:25
An example of custom For syntax... Pretty dumb... Just messing around...
using System;
namespace Example
{
class Program
{
static void Main()
{
For (10..5)
(
@ZacharyPatten
ZacharyPatten / AlgorithmChecker.cs
Last active December 3, 2019 21:00
Temporary algorithm checker.
using System;
using System.Linq;
using System.Collections.Generic;
namespace ConsoleCoreSandbox
{
class Program
{
static void Main()
{