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
# | |
# from: https://devonburriss.me/up-and-running-with-paket | |
# | |
# If you find yourself needing to setup Paket often as can happen if you are using F# fsx scripting files often, | |
# you may want to create an easier to remember command. The easiest way to do this is to add a function call to | |
# your Powershell profile. | |
# | |
# Edit "C:\Users\<your username>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1" on Windows | |
# or ~/.config/powershell/profile.ps1 on Mac and add the following function: |
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
// This is am example of an immediate write / random access cursor for Excel with basic formatting options. | |
// Implementation is based on a concrete, non generic writer monad with no payload ("do!"" only) (only state). | |
// Instead of directl writing to excel, an alternatives would be a random acces to a | |
// copy-on-write list (or even a mutable array) and then bulk-write the result to excel in one shot. | |
// When only forward access would have been required, a simple seq expression with yields would have been enough. | |
// Anyway, it is a demonstration on how to "hide" pseudo-mutable state that is passed through a computation. | |
// | |
// I personally use it for generating reports based on various data sources. |
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 RowPointer = int | |
type Writer = Writer of (RowPointer -> RowPointer) | |
let run (f:Writer) = match f with | Writer f -> f | |
type Cursor() = | |
member this.Bind(m: Writer, f: unit -> Writer) = | |
Writer(fun rp -> | |
let res = f() |> run | |
let newRp = rp |> run m |
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
// extend a type from another assembly with 'combine' | |
type List<'a> with | |
static member combine (f, x: List<'a>) : List<'a> = x @ [f] | |
// extend another type from another assembly with 'combine' | |
type System.Int32 with | |
static member combine (f, x: System.Int32) = x + f | |
// extend a type from this assembly with 'combine' |
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.IO | |
let curry (f: (_ * _ -> _)) a b = f (a,b) | |
let curry2 = curry | |
let curry3 (f: (_ * _ * _ -> _)) a b c = f (a,b,c) | |
let curry4 (f: (_ * _ * _ * _ -> _)) a b c d = f (a,b,c,d) | |
let ( <+> ) a b = Path.Combine(a, b) |
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
// paket FsHttp | |
open FSharp.Data | |
open FSharp.Data.JsonExtensions | |
open FsHttp | |
open FsHttp.Dsl | |
let call s = |
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 | |
open System.Reflection | |
open System.Collections | |
open System.Collections.Generic | |
// TODO: Allow linebreaks in cells for strings / sequences? | |
module Config = | |
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
// Grenzen? | |
let toRoman arabic = | |
let repeatChar char num = | |
List.init num id | |
|> List.fold (fun curr _ -> sprintf "%s%s" char curr) "" | |
let zehnerUndHöher = arabic / 10 | |
let einer = arabic % 10 |
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
from functools import reduce | |
def convertToRoman(num): | |
roman_factors = [(1000, 'M'), (900, 'CM'), (500, 'D'), (400, 'CD'), (100, 'C'), (90, 'XC'), (50, 'L'), (40, 'XL'), (10, 'X'), (9, 'IX'), (5, 'V'), (4, 'IV'), (1, 'I') ] | |
return reduce(lambda state, factor: (state[0] % factor[0], state[1] + factor[1] * (state[0] // factor[0])), [(num, '')] + roman_factors)[1] | |
print(convertToRoman(2049)) |
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 'a Foo = Foo of 'a | |
module Foo = | |
let ofValue (a : 'a) : 'a Foo = Foo a | |
let apply (a : 'a Foo) (f : ('a -> 'b) Foo) : 'b Foo = | |
let (Foo f) = f | |
let (Foo a) = a | |
Foo (f a) |
OlderNewer