From 493845a213ac238fbba0e401f4cf15b9659ec7f6 Mon Sep 17 00:00:00 2001 From: Araozu Date: Sun, 26 May 2024 16:08:11 -0500 Subject: [PATCH] Change the code sample in the landpage --- src/pages/index.astro | 27 ++++++++++++++------------ src/pages/learn/error-handling/try.mdx | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index 587b858..7fe69e9 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -100,25 +100,28 @@ import Navbar from "../components/Navbar.astro"; }); jar.updateCode( - `// Actual generics & sum types -fun find_person(Int person_id) -> Result[String, String] { -// Easy, explicit error bubbling -try Person::find_by_id(person_id) + `// Sum types +enum Animal { + Dog(String), + Cat(String, Int), } -val id = POST::get("person_id") ?? exit("Null person_id") -// Errors as values -val person = try find_person(person_id: id) with error { -eprint("Error: {error}") -exit("Person not found") -} +// Null safety +val cat_name = Post::get("cat_name") ?? "Michi" +val cat1 = Animal::Cat(cat_name, 9) + +// 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 -print( welcome, {person.name} -) // And more!`, ); diff --git a/src/pages/learn/error-handling/try.mdx b/src/pages/learn/error-handling/try.mdx index ac2871e..49bf7fa 100644 --- a/src/pages/learn/error-handling/try.mdx +++ b/src/pages/learn/error-handling/try.mdx @@ -151,7 +151,7 @@ In the previous example: ### Try/else -Try/return will assign a new value if an expression fails. +Try/else will assign a new value if an expression fails.