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 s = "Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53" | |
// challenge - split above into values we can reason about e.g. | |
type Card = { | |
Id : int // 1 | |
Winning : int list // 41 48 83 86 17 | |
Ticket : int list // 83 86 6 31 17 9 48 53 | |
} |
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
type ThingConverter() = | |
interface IValueConverter with | |
member x.Convert(value, _, _, _) = if (value.ToString()) = "Joe Bloggs" then (10. :> obj) else (20. :> obj) | |
member x.ConvertBack(_, _, _, _) = null | |
// This converter will always fail and just return 0. | |
type CustomThingConverter() = | |
inherit Converter<string, float>((fun value _ -> if value = "Joe Bloggs" then 10. else 20.), 0.) |
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
module List = | |
let partitionMap partitioner = | |
let rec loop (acc1, acc2) = function | |
| [] -> List.rev acc1, List.rev acc2 | |
| x::xs -> | |
match partitioner x with | |
| Choice1Of2 y -> loop (y::acc1, acc2) xs | |
| Choice2Of2 y -> loop (acc1, y::acc2) xs | |
loop ([], []) |
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
#load @".paket\load\net452\FSharpPlus.fsx" | |
open FSharpPlus | |
open System | |
[<AutoOpen>] | |
module rec IO = | |
let run (IO computation) = computation() | |
type IO<'T> = |
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
// Change this to your profile folder for nuget packages | |
#I @"C:\Users\Isaac\.nuget\packages\" | |
#r @"XPlot.GoogleCharts\2.0.0\lib\netstandard2.0\XPlot.GoogleCharts.dll" | |
#r @"Newtonsoft.Json\12.0.3\lib\netstandard2.0\Newtonsoft.Json.dll" | |
#r @"Google.DataTable.Net.Wrapper\4.0.0\lib\netstandard2.0\Google.DataTable.Net.Wrapper.dll" | |
open System | |
open XPlot.GoogleCharts | |
/// Executes an asynchronous workflow and provides some simple statistics on the results. |
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 | |
/// A train carriage can have a number of different features... | |
type Feature = Quiet | Wifi | Toilet | |
/// Multiple classes | |
type CarriageClass = First | Second | |
/// Carriages can be either for passengers or the buffet cart | |
type CarriageKind = |
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
// F# version of https://twitter.com/gsferreira/status/1516827091127394309/ | |
open System | |
open System.IO | |
type PotentialProcessingError = StringMissing | StringTooShort | |
let application (str: string) = | |
match str with | |
| str when str.Length < 5 -> Error StringTooShort |
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
namespace ClassLibrary1; | |
public static class LinqExtensions | |
{ | |
public static IEnumerable<TOut> Choose<T, TOut>(this IEnumerable<T> input, Func<T, TOut?> chooser) | |
{ | |
foreach (var i in input) | |
{ | |
var c = chooser(i); | |
if (c is { } q) | |
{ |
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
namespace Newtonsoft.Json.Converters | |
open Microsoft.FSharp.Reflection | |
open Newtonsoft.Json | |
open System | |
type IdiomaticDuConverter() = | |
inherit JsonConverter() | |
[<Literal>] |
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
#r "nuget:FSCheck" | |
open FsCheck | |
open System | |
type TurnDirection = Left | Right | |
type MoveDirection = Forward | Back | |
type Direction = N | S | E | W | |
type Coordinates = { X : int; Y : int } | |
type State = |
NewerOlder