Skip to content

Instantly share code, notes, and snippets.

@AmadorMunozBerzosa
AmadorMunozBerzosa / ActivePatterns.fs
Last active June 19, 2021 16:36
DSL wrapper for working with regular expressions in a readable manner in F#. Gist messes with the file ordering, but the correct file order is: Types > Evaluation > Operators > ActivePatterns > Examples
module Krow.Regex.ActivePatterns
open System.Text
let (|Regex|_|) (pattern:IRegex) input =
if input = null then
None
else
try
let match' = RegularExpressions.Regex.Match(input, pattern |> Regex.evaluate)
@battermann
battermann / io.fsx
Last active July 6, 2020 15:21
IO Monad in F#
[<AutoOpen>]
module IO =
type IO<'a> =
private
| Return of (unit -> 'a)
| Suspend of (unit -> IO<'a>)
let rec run x =
match x with
| Return v -> v()
@jwosty
jwosty / StateBuilder.fsx
Created March 24, 2016 23:44
F# state monad / computation expression builder, and example usage
open System
open System.IO
type State<'s, 'a> = State of ('s -> ('a * 's))
module State =
let inline run state x = let (State(f)) = x in f state
let get = State(fun s -> s, s)
let put newState = State(fun _ -> (), newState)
let map f s = State(fun (state: 's) ->