Skip to content

Instantly share code, notes, and snippets.

View SchlenkR's full-sized avatar

SchlenkR SchlenkR

View GitHub Profile
@SchlenkR
SchlenkR / gist:5b698385f19ee1aeff8e520bb1d9830b
Created April 22, 2024 14:01
SRTP Operator Overloading Hack
type Kickoff = Kickoff with
static member inline ($) (Kickoff, x: FsHttp.DslCE.LazyHttpBuilder<'context>) =
x |> Request.send
static member inline ($) (Kickoff, x: FsHttp.Domain.IToRequest) =
x |> Request.send
let inline kickoff x = (($) Kickoff) x
let inline (~%) x = kickoff x
(*
Script for the Video:
"Roll Your Own „For“-Comprehension: Column-Wise, Not Nested"
YT-Link: https://www.youtube.com/watch?v=Qs8Z4B19ha0
*)
// Given:
let seq1 = [ 1; 2; 3 ]
#r "nuget: FsHttp"
#r "nuget: FSharp.Data"
open FsHttp
open FsHttp.Operators
open FSharp.Data
let url = "https://public-api.wordpress.com/wpcom/v2/sites/15048173/articles
?className=is-style-borders
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"background": "#c386f1",
"foreground": "#ffffff",
"leading_diamond": "\ue0b6",
@SchlenkR
SchlenkR / MaxOneYield_ExactlyOneYield.fsx
Created January 17, 2023 12:43
2 examples of CE builders allowing a maximum of 1 yield or require exactly 1 yield
module MaxOneYield =
// --------------------------------------------
// Recipe for a builder that limits
// the number of yields to a maximum of one.
// --------------------------------------------
// We need a distinct type for a "Zero" element.
type ZeroChild = ZeroChild
type MaxOneChildBuilder() =
@SchlenkR
SchlenkR / statefulSeqBuilder.fsx
Last active January 6, 2023 10:09
Since the typical CE builder is a singleton with keyword-like semantics, the builder instance cannot carry it's own state. As a workaround, we can model the state (mutable in this case) and pass it along the computation (omehow a reader monad-like thing with with unit as result type + mutation). The "Run" builder method is then the instanciation…
/// Pseudo custom operation that can be yielded
type Ops =
| Clear
// Since the typical CE builder is a singleton with keyword-like
// semantics, the builder instance cannot carry it's own state.
// As a workaround, we can model the state (mutable in this case)
// and pass it along the computation (omehow a reader monad-like
// thing with with unit as result type + mutation).
// The "Run" builder method is then the instanciation of the
@SchlenkR
SchlenkR / Test.fs
Last active August 31, 2022 12:00
FslangSuggestion1178
module FslangSuggestion1178
type Hero =
| AH
| GM
| NT
module Hero =
let inline convert x =
function
@SchlenkR
SchlenkR / demo.md
Created November 30, 2021 20:38
F# Markdown für Vadim

Kochen mit Ronald

Super einfache Rezepte

Spaghetticode

var x = 10
@SchlenkR
SchlenkR / funcyDownEx.fsx
Created November 27, 2021 18:19
FuncyDown extension
#r "nuget: FuncyDown"
open FuncyDown.Element
open FuncyDown.Document
module ReadmeSample =
let badges =
"""
[![license](https://img.shields.io/github/license/GDATASoftwareAG/FuncyDown.svg)](https://raw.githubusercontent.com/GDATASoftwareAG/FuncyDown/master/LICENSE)
module ListComprehensions
// sehr einfach!
let result =
let a = 10
let b = 20
let c = 30
a + b + c
// könnte man auch so schreiben: