Change the code sample in the landpage
This commit is contained in:
parent
79bdee91d0
commit
493845a213
@ -100,25 +100,28 @@ import Navbar from "../components/Navbar.astro";
|
|||||||
});
|
});
|
||||||
|
|
||||||
jar.updateCode(
|
jar.updateCode(
|
||||||
`// Actual generics & sum types
|
`// Sum types
|
||||||
fun find_person(Int person_id) -> Result[String, String] {
|
enum Animal {
|
||||||
// Easy, explicit error bubbling
|
Dog(String),
|
||||||
try Person::find_by_id(person_id)
|
Cat(String, Int),
|
||||||
}
|
}
|
||||||
|
|
||||||
val id = POST::get("person_id") ?? exit("Null person_id")
|
// Null safety
|
||||||
// Errors as values
|
val cat_name = Post::get("cat_name") ?? "Michi"
|
||||||
val person = try find_person(person_id: id) with error {
|
val cat1 = Animal::Cat(cat_name, 9)
|
||||||
eprint("Error: {error}")
|
|
||||||
exit("Person not found")
|
// Errors as values, easy handling
|
||||||
}
|
val cat2 = try clone_cat(cat) else die("Not a cat")
|
||||||
|
|
||||||
|
// Pattern matching
|
||||||
|
match random_animal()
|
||||||
|
case Dog(name) { print("{name} has 1 live ") }
|
||||||
|
case Cat(name, lives) { print("{name} has {lives}") }
|
||||||
|
|
||||||
// First class HTML-like templates & components
|
// First class HTML-like templates & components
|
||||||
print(
|
|
||||||
<a href="/person/reports/{person.id}">
|
<a href="/person/reports/{person.id}">
|
||||||
welcome, {person.name}
|
welcome, {person.name}
|
||||||
</a>
|
</a>
|
||||||
)
|
|
||||||
// And more!`,
|
// And more!`,
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
@ -151,7 +151,7 @@ In the previous example:
|
|||||||
|
|
||||||
### Try/else
|
### Try/else
|
||||||
|
|
||||||
Try/return will assign a new value if an expression fails.
|
Try/else will assign a new value if an expression fails.
|
||||||
|
|
||||||
<InteractiveCode
|
<InteractiveCode
|
||||||
code={`
|
code={`
|
||||||
|
Loading…
Reference in New Issue
Block a user