Skip to content

Instantly share code, notes, and snippets.

View altbodhi's full-sized avatar
🏠
Working from home

altbodhi

🏠
Working from home
View GitHub Profile
@altbodhi
altbodhi / io.fsx
Created August 22, 2019 09:52
F# implements write and writeln like as turbo pascal
open System
open Microsoft.FSharp.Reflection
let readln = Console.ReadLine
let writeln = fun a ->
let args = if FSharpType.IsTuple(a.GetType()) then FSharpValue.GetTupleFields(a) else [|a|]
let fmt = args |> Array.indexed |> Array.fold (fun s e -> s + (sprintf "{%d}" (fst e))) ""
Console.WriteLine(fmt.Trim(), args)
let write = fun a ->
let args = if FSharpType.IsTuple(a.GetType()) then FSharpValue.GetTupleFields(a) else [|a|]
@altbodhi
altbodhi / progress.fsx
Created September 21, 2018 09:19
Test work IProgress interface in fs
open System.IO
open System.Net
open System.Text
open System
let httpAsync (progress : IProgress<string>) (url : string) = async {
let req = System.Net.WebRequest.Create(url)
use! resp = req.AsyncGetResponse()
progress.Report(sprintf "%s AsyncGetResponse" url)
use stream = resp.GetResponseStream()