Change the code sample in the landpage

This commit is contained in:
Araozu 2024-05-26 16:08:11 -05:00
parent 79bdee91d0
commit 493845a213
2 changed files with 16 additions and 13 deletions

View File

@ -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>

View File

@ -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={`