This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Entity<TId> : IEquatable<Entity<TId>> | |
{ | |
private readonly TId _id; | |
protected Entity(TId id) | |
{ | |
if (object.Equals(id, default(TId))) | |
{ | |
throw new ArgumentException("The ID cannot be the default value.", nameof(id)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ICircuitBreaker | |
{ | |
TResult Execute(Func action); | |
void Execute(Action action); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Find the sum of all the multiples of 3 or 5 below 1000. | |
[1..999] | |
|> List.filter (fun x -> x % 3 = 0 || x % 5 = 0) | |
|> List.sum | |
//Almost identical to http://theburningmonk.com/2010/09/project-euler-problem-1-solution/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Find the sum of all the even-valued terms in the Fibonacci sequence which do not exceed four million. | |
let fibonacciSequence = Seq.unfold(fun (a, b) -> Some(a + b, (b, a + b))) (0L, 1L) | |
fibonacciSequence | |
|> Seq.takeWhile (fun x -> x < 4000000L) | |
|> Seq.filter (fun x -> x % 2L = 0L) | |
|> Seq.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let isPrime (n : int64) = | |
let upperBound = n |> float |> sqrt |> int64 | |
seq {2L .. upperBound} | |
|> Seq.forall (fun x -> n % x <> 0L) | |
let getAllFactors (n : int64) = | |
let upperBound = n / 2L | |
seq {2L .. upperBound} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A palindromic number reads the same both ways. | |
//The largest palindrome made from the product of two | |
//2-digit numbers is 9009 = 91 × 99. | |
//Find the largest palindrome made from the product of | |
//two 3-digit numbers. | |
open System | |
let noOfDigits = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Based on Jake Harry's article on generating palindromes http://www.p196.org/papers10.html | |
open System | |
let getDistanceFromNextHundred n = | |
100 - (n % 100) | |
let getTensForAddition n = | |
Math.Ceiling(float n/ 10.) * 10. | |
|> int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Disposables; | |
using System.IO; | |
using System.Linq; | |
using System.Net; | |
using System.Reflection; | |
using Funq; | |
using ServiceStack.Common.Web; | |
using ServiceStack.Service; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class EventStoreConnectionExtensions | |
{ | |
public static Task<EventStoreRxSubscription> SubscribeToAll(this EventStoreConnection connection, bool resolveLinkTos) | |
{ | |
return Task<EventStoreRxSubscription>.Factory.StartNew(() => { | |
var subject = new Subject<ResolvedEvent>(); | |
var subscriptionTask = connection.SubscribeToAll(resolveLinkTos, subject.OnNext, () => subject.OnError(new SubscriptionDroppedException())); | |
subscriptionTask.Wait(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
let isDivisibleBy seq n = | |
seq | |
|> Seq.forall (fun x -> n % x = 0) | |
Seq.unfold (fun x -> Some(x, x + 20)) 20 | |
|> Seq.find (isDivisibleBy [|1 .. 20|]) |
OlderNewer