feat: docs
This commit is contained in:
parent
4c4be43cb0
commit
63ef3c0b5e
@ -12,7 +12,7 @@ const error_classes = "underline underline-offset-4 decoration-wavy decoration-r
|
|||||||
* - The tokens as a list of <span /> elements
|
* - The tokens as a list of <span /> elements
|
||||||
* - An error message, if any
|
* - 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");
|
let formatted_code = leftTrimDedent(code).join("\n");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -42,5 +42,16 @@ case 1, 2, 3 {
|
|||||||
else {
|
else {
|
||||||
print("hello dear")
|
print("hello dear")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
match customer_id
|
||||||
|
| 1 | 2 | 3 {
|
||||||
|
print("ehhhh")
|
||||||
|
}
|
||||||
|
| 4 | 5 {
|
||||||
|
print("ohhh")
|
||||||
|
}
|
||||||
|
| _ {
|
||||||
|
print("???")
|
||||||
|
}
|
||||||
`} />
|
`} />
|
||||||
|
|
||||||
|
52
src/pages/en/latest/learn/03_flow-control/pipes.mdx
Normal file
52
src/pages/en/latest/learn/03_flow-control/pipes.mdx
Normal 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
|
||||||
|
`} />
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user