var x = 10
var y = 20
var z = x + y
Hello, this is Vadim.
My skills are:
- This
- That
- Whatever
(* | |
- Header (n-stufig) | |
- Codeblöcke | |
- Textblöcke | |
- Listen | |
*) | |
(* | |
<markdown> | |
<h1>Kochen mit Ronald</h1> | |
<h2>Super einfache Rezepte</h2> | |
<bullet> | |
<item>This</item> | |
<item>...</item> | |
</bullet> | |
<code lang="csharp"> | |
var x = 10 | |
var y = 20 | |
var z = x + y | |
</code> | |
</markdown> | |
*) | |
// 2 Wege (gibt prinzipiell noch mehr) | |
// 1. Datenmodell definieren; Funktionen auf Daten, die "rendern" | |
// 2. Funktionen definieren, die direkt rendern | |
// ------ | |
// Weg 2 | |
// ------ | |
// Wir habe Textzeiln. | |
// Jede Funktion nimmt irgendetwas entgegen und evaluiert zu einer Liste von strings. | |
// Diese Strings werden zum Schluss zusammengesetzt ("eine Liste von Funktionen") und ergeben das finale Dokument. | |
(* | |
let document = | |
h1 "Kochen mit Ronald" | |
h2 "Super einfache Rezepte" | |
bullet | |
"This" | |
"that" | |
"Hello, this is Vadim." | |
"My skills are:" | |
code lang="csharp" | |
""" | |
var x = 10 | |
var y = 20 | |
var z = x + y | |
""" | |
render document | |
*) | |
// let h1 (text: string) = $"{text}\n===" | |
let h1 (text: string) = | |
[ | |
yield text | |
yield "===" | |
yield "" | |
] | |
let h2 (text: string) = | |
[ | |
yield text | |
yield "---" | |
yield "" | |
] | |
let hn level (text: string) = | |
[ | |
yield (String.replicate level "#") + $" {text}" | |
] | |
let bullet (items: list<string>) = | |
[ | |
for x in items do | |
$"* {x}" | |
"" | |
] | |
// items |> List.map (fun x -> $"* {x}") | |
let code lang text = | |
[ | |
$"``` %s{lang}" | |
text | |
"```" | |
"" | |
] | |
let text = List.singleton | |
// List.singleton "sdfsdf" | |
// text "sdfsdf" | |
let document = [ | |
h1 "Kochen mit Ronald" | |
h2 "Super einfache Rezepte" | |
bullet [ | |
"This" | |
"that" | |
] | |
text """ | |
Hello, this is Vadim. | |
My skills are: | |
""" | |
code "csharp" """ | |
var x = 10 | |
var y = 20 | |
var z = x + y | |
""" | |
] | |
let render document = | |
// document | |
// .SelectMany(id) | |
// .Select(fun line -> line + "\n") | |
// .Aggregate(fun a b -> a + b) | |
document | |
|> List.collect id | |
|> List.map (fun line -> line + "\n") | |
|> List.fold (+) "" | |
// TODO: Alternative mit yield! | |
let finalDoc = render document | |
// ------------------- | |
// Off-Topic / Exkurs: | |
// ------------------- | |
let getAllNames (friends: list<string>) = | |
[ | |
yield "Vadim" | |
// for friend in friends do | |
// yield friend | |
yield! friends | |
yield "Ronald" | |
yield "Jana" | |
] | |
getAllNames [ "Hans"; "Peter"; "Erika" ] | |
// seq { | |
// yield "Hallo" | |
// yield "Vadim" | |
// } | |
// [| | |
// yield "Hallo" | |
// yield "Vadim" | |
// |] | |
// [| | |
// for i in 1..10 do | |
// yield i + 100 | |
// |] | |
// public IEnumerable<string> GetStrings() { | |
// yield return "Hallo"; | |
// yield return "Vadim"; | |
// } |