feat: docs

This commit is contained in:
Araozu 2024-11-22 07:09:32 -05:00
parent 4c4be43cb0
commit 63ef3c0b5e
3 changed files with 64 additions and 1 deletions

View File

@ -12,7 +12,7 @@ const error_classes = "underline underline-offset-4 decoration-wavy decoration-r
* - The tokens as a list of <span /> elements
* - An error message, if any
*/
export async function native_highlighter(code: string, level = HighlightLevel.Syntactic): Promise<[string, string | null]> {
export async function native_highlighter(code: string, level = HighlightLevel.Lexic): Promise<[string, string | null]> {
let formatted_code = leftTrimDedent(code).join("\n");
try {

View File

@ -42,5 +42,16 @@ case 1, 2, 3 {
else {
print("hello dear")
}
match customer_id
| 1 | 2 | 3 {
print("ehhhh")
}
| 4 | 5 {
print("ohhh")
}
| _ {
print("???")
}
`} />

View File

@ -0,0 +1,52 @@
---
layout: "../_wrapper.astro"
title: Pipes
---
import Code from "@/components/Code.astro"
# Pipes
You can use pipes `|>` & `<|` to redirect output from an
expression as input to another.
For example, instead of writing:
<Code thpcode={`
val result = third_function(second_function(first_function(my_value)))
`} />
You can use pipes:
<Code thpcode={`
val result = my_value
|> first_function
|> second_function
|> third_function
`} />
Or use it to group expressions:
<Code thpcode={`
print <| (2 + 3 * 4) / 7
`} />
TBD: How to handle piping to functions with more than 1 param
## Function composition
<Code thpcode={`
fun add_one(x: Int) -> Int {
x + 1
}
fun times_two(x: Int) -> Int {
x * 2
}
// (Int) -> (Int)
val plus_one_times_2 = add_one >> times_two
print(plus_one_times_2(5)) // 12
`} />