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
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
// 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
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
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
#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 = |
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 Decorators = | |
type FnDetails<'T> = { Name : string; Args : 'T } | |
type DecoratedFunction<'a, 'b> = FnDetails<'a> -> 'b | |
/// Logs the arguments and result of any function call. | |
let logger next details = | |
fooLogger.LogInformation ("Inside {Name}, Args {Args}", details.Name, details.Args) | |
let result = next details | |
fooLogger.LogInformation ("Result was {Result}.", $"%A{result}") | |
result |
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 | |
/// Asynchronously loads some data from the DB | |
let fetchDataFromDb () = async { | |
printfn "Loading DB data..." | |
return 99 | |
} | |
let random = Random() |
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: SchlenkR.FsHttp" | |
open FsHttp.DslCE | |
type Switch = On | Off member this.AsBool = match this with On -> true | Off -> false | |
type LightId = LightId of int | |
module Cmd = | |
let username = "<access username>" | |
let ip = "<local ip address>" |
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 Meadow | |
open System | |
open System.Threading | |
open Meadow.Devices | |
open Meadow.Foundation | |
open Meadow.Foundation.Leds | |
module HelloWorld = | |
let colors = [ Color.AliceBlue; Color.AntiqueWhite; Color.Black; Color.DarkGray; Color.Cyan; Color.Green; Color.GreenYellow; Color.Yellow; Color.Orange; Color.OrangeRed; Color.Red; Color.MediumVioletRed; Color.Purple; Color.Magenta; Color.Pink ] |
NewerOlder