diff --git a/src/pages/en/latest/learn/basics/operators.mdx b/src/pages/en/latest/learn/basics/operators.mdx
index bbe8963..6561668 100644
--- a/src/pages/en/latest/learn/basics/operators.mdx
+++ b/src/pages/en/latest/learn/basics/operators.mdx
@@ -111,8 +111,7 @@ person?.name
person?.name ?? "Jane"
person?.greet?.()
-if person?
-{
+if person? {
person.name
}
`} />
diff --git a/src/pages/en/latest/learn/classes/anonymous.mdx b/src/pages/en/latest/learn/classes/anonymous.mdx
index fe39986..e9c6619 100644
--- a/src/pages/en/latest/learn/classes/anonymous.mdx
+++ b/src/pages/en/latest/learn/classes/anonymous.mdx
@@ -8,10 +8,8 @@ import Code from "@/components/Code.astro"
SomeClass(param1), SomeInterface
-{
- pub fun method()
- {
+setLogger(class(Int param1) -> SomeClass(param1), SomeInterface {
+ pub fun method() {
// code
}
})
diff --git a/src/pages/en/latest/learn/classes/constructor.mdx b/src/pages/en/latest/learn/classes/constructor.mdx
index f8a4c4d..88e726a 100644
--- a/src/pages/en/latest/learn/classes/constructor.mdx
+++ b/src/pages/en/latest/learn/classes/constructor.mdx
@@ -55,13 +55,11 @@ The `init` block allow us to run code during the
construction of the instance:
Error!
- {
+throws Error {
+ init -> Error! {
// Initialization code that may fail
}
}
@@ -156,10 +152,8 @@ throws Error
The destructor in THP is the same as PHP.
String
- {
+ pub fun get_name() -> String {
return $name
}
- pub fun greet()
- {
+ pub fun greet() {
val person_name = $get_name()
print("Hello, I'm {person_name}")
}
@@ -166,10 +155,8 @@ class Person()
By default methods cannot mutate the state of the object.
@@ -52,13 +48,11 @@ TBD
0
-{
+if Some(user_id) = user_id && user_id > 0 {
print("user_id is greater than 0: {user_id}")
}
`} />
diff --git a/src/pages/en/latest/learn/flow-control/loops.mdx b/src/pages/en/latest/learn/flow-control/loops.mdx
index a9c69f7..b63a648 100644
--- a/src/pages/en/latest/learn/flow-control/loops.mdx
+++ b/src/pages/en/latest/learn/flow-control/loops.mdx
@@ -17,8 +17,7 @@ Braces are required.
@@ -30,8 +29,7 @@ val dict = .{
cherries: 3,
}
-for value in dict
-{
+for value in dict {
print("{value}")
}
`} />
@@ -42,8 +40,7 @@ for value in dict
@@ -55,8 +52,7 @@ val dict = .{
cherries: 3,
}
-for key, value in dict
-{
+for key, value in dict {
print("{key} => {value}")
}
`} />
@@ -68,8 +64,7 @@ for key, value in dict
val colors = ["red", "green", "blue"]
var index = 0
-while index < colors.size()
-{
+while index < colors.size() {
print("{colors[index]}")
index += 1
}
@@ -83,10 +78,8 @@ TBD
You can give labels to loops, allowing you to `break` and `continue` in nested loops.
0
-{
+case Some(id) if id > 0 {
print("user_id exists: {id}")
}
-else
-{
+else {
print("user_id has other values ")
}
match customer_id
-case 1, 2, 3
-{
+case 1, 2, 3 {
print("special discount for our first 3 customers!")
}
-else
-{
+else {
print("hello dear")
}
`} />
diff --git a/src/pages/index.astro b/src/pages/index.astro
index 7de8e1e..1e608d3 100644
--- a/src/pages/index.astro
+++ b/src/pages/index.astro
@@ -14,12 +14,10 @@ const thpcode = `union Animal {
val my_pet = try Pets::get_first()
match my_pet
-case Dog(name)
-{
+case Dog(name) {
print("{name} has 1 live ")
}
-case Cat(name, lives)
-{
+case Cat(name, lives) {
print("{name} has {lives}")
}`;
@@ -177,12 +175,10 @@ const [thp_html] = await native_highlighter(
thpcode={`
match test_file
case DirEntry::File(filename)
- if !filename.starts_with(".")
- {
+ if !filename.starts_with(".") {
print(filename)
}
- case _
- {
+ case _ {
print("A valid file was not found")
}
`}
@@ -196,9 +192,8 @@ const [thp_html] = await native_highlighter(
title="Null safety"
thpcode={`
String? username = Post::get("username")
-
- if username?
- {
+
+ if username? {
// username is a \`String\` here
print("Hello, {username}")
}
@@ -215,8 +210,7 @@ const [thp_html] = await native_highlighter(
thpcode={`
val user_id = POST::get("id")
val user = try User::find(user_id)
- catch DBException e
- {
+ catch DBException e {
log_error(e.message)
return page(.{}, 404)
}