Given a big domain of types that don't implement IEquatable, e.g (simplified here):
class A {
public int a;
public string b;
public IEnumerable<int?> c;
public IEnumerable<B> d;
}
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
/* | |
Closest things I found are http://stackoverflow.com/q/3835633 or http://stackoverflow.com/q/7188623 | |
but the solutions there either handle exceptions with a side effect (an Action<Exception>) or just filter out the exceptions or are limited in other ways. | |
This also continues enumeration after exceptions until the end of the IEnumerable, accumulating both values and exceptions. | |
It's useful to wrap sequences modeling potentially partial lazy computations. |
using Castle.Core; | |
using Castle.MicroKernel; | |
using Castle.MicroKernel.ModelBuilder.Descriptors; | |
using Castle.MicroKernel.Registration; | |
using Castle.MicroKernel.SubSystems.Configuration; | |
using Castle.Windsor; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; |
module String = | |
open System.Text.RegularExpressions | |
///Makes a string suitable for use as part of a URL: | |
///Removes syntax, replaces spaces with dashes and lowers case, | |
///then trims first word after 30 chars | |
let prettify (x:string) = | |
let parsed = Regex.Replace(x.Trim(),"[^0-9a-zA-Z ]","").Replace(" ","-").ToLower() |
using System; | |
public abstract class Term { | |
private Term() { } | |
public abstract T Match<T>(Func<Var, T> var, Func<App, T> app, Func<Fun, T> fun); | |
// TODO: equality, ToString() | |
/// <summary> |
Module Module1 | |
Sub Foo(Of T)(xs As T(), f As Func(Of T, Boolean)) | |
End Sub | |
Sub Main() | |
Foo({1}, Function(x) True) | |
End Sub | |
End Module |
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Data.SqlClient; | |
using System.Linq; | |
class Program { | |
static void Main(string[] args) { | |
var s = new Sql("SELECT * FROM TABLE WHERE Id = ") + Sql.P(1) + " and Name = " + Sql.P("John Doe"); |
Given a big domain of types that don't implement IEquatable, e.g (simplified here):
class A {
public int a;
public string b;
public IEnumerable<int?> c;
public IEnumerable<B> d;
}
using System; | |
using System.Linq; | |
static class Program { | |
static void Main(string[] args) { | |
var a = new int?[] { 1, 2, null, 4 }; | |
{ | |
// "Where" here does not change the output type. Pass it to some other function and the information about this filter is lost, | |
// i.e. "You made no reusable note of what you did." ( http://www.hxa.name/notes/note-hxa7241-20131124T0927Z.html ) |
using System; | |
using System.Linq; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var source = new int[0]; | |
// throws InvalidOperationException, not documented in http://msdn.microsoft.com/en-us/library/bb534962.aspx . Should not even compile as AStruct doesn't implement IComparable. |
using System; | |
static class L { | |
public static Func<T> F<T>(Func<T> f) { return f; } | |
// add overloads for other arities | |
} | |
class Program { | |
static void Main(string[] args) { | |
int i = L.F(() => 0)(); |