Skip to content

Instantly share code, notes, and snippets.

View MelbourneDeveloper's full-sized avatar
🏠
Working from home

Christian Findlay MelbourneDeveloper

🏠
Working from home
View GitHub Profile
@MelbourneDeveloper
MelbourneDeveloper / expvsstat.cs
Created October 17, 2020 04:29
Expressions Vs Statements
public static string ToUppercaseExpression(this string currentString) =>
new string(currentString.Select(c => (char)(c < 97 || c > 122 ? c : c - 32)).ToArray());
public static string ToUppercaseStatements(this string currentString)
{
var returnValue = new StringBuilder();
foreach(var c in currentString)
{
if(c < 97 || c > 122)
{
using Microsoft.FSharp.Collections;
using System;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
var numbers = FSharpList<int>.Cons(
let query1 =
query {
for customer in db.Customers do
select customer
}
@MelbourneDeveloper
MelbourneDeveloper / Point.cs
Created October 17, 2020 05:01
F# Point Record as C#
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Microsoft.FSharp.Core;
namespace FSharpLibrary
{
// Token: 0x02000002 RID: 2
[CompilationMapping(SourceConstructFlags.RecordType)]
@MelbourneDeveloper
MelbourneDeveloper / CsharpPoint.cs
Created October 17, 2020 05:06
C# Point Record
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
namespace FSharpFromCSharp
{
// Token: 0x02000006 RID: 6
public class CsharpPoint : IEquatable<CsharpPoint>
{
// Token: 0x06000006 RID: 6 RVA: 0x0000209B File Offset: 0x0000029B
@MelbourneDeveloper
MelbourneDeveloper / ShapeDS.cs
Created October 17, 2020 06:59
C# Use Discriminated Union
static void Main(string[] args)
{
FSharpLibrary.Shape shape = FSharpLibrary.Shape.NewCircle(1);
Console.WriteLine($"Is this a rectangle: {shape.IsRectangle}");
}
@MelbourneDeveloper
MelbourneDeveloper / Shape.fs
Last active October 17, 2020 07:00
F# Shape Discriminated Union
type Shape =
| Rectangle of width : float * length : float
| Circle of radius : float
| Prism of width : float * float * height : float
@MelbourneDeveloper
MelbourneDeveloper / PubSub.cs
Last active October 24, 2020 02:27
An example of simple messaging with observables
/*
One: Hi
Two: Hi
One: Hi
Two: Hi
One: Hi
Two: Hi
One: Hi
Two: Hi
One: Hi
@MelbourneDeveloper
MelbourneDeveloper / PubSub2.cs
Last active October 24, 2020 02:35
An example of simple messaging with observable
/*
Name: One Message: Hi
Name: Two Message: Hi
Name: One Message: Hi
Name: Two Message: Hi
Name: One Message: Hi
Name: Two Message: Hi
Name: One Message: Hi
Name: Two Message: Hi
Name: One Message: Hi
@MelbourneDeveloper
MelbourneDeveloper / PubSub3.cs
Created October 24, 2020 05:19
This version creates two threads and loops. It's no good.
/*
Name: One Message: Hi
Name: Two Message: Hi
Name: One Message: Hi
Name: Two Message: Hi
Name: One Message: Hi
Name: Two Message: Hi
Name: Two Message: Hi
Name: One Message: Hi
Name: Two Message: Hi