From c2dcbe0f25a3e8bd60a4ccf377bbdd47f4794871 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Tue, 26 Mar 2024 13:57:31 +0000 Subject: Document opaque types Closes https://github.com/gleam-lang/language-tour/issues/63 --- .../lesson00_use/code.gleam | 38 ---------------------- .../lesson00_use/en.html | 31 ------------------ 2 files changed, 69 deletions(-) delete mode 100644 src/content/chapter5_advanced_features/lesson00_use/code.gleam delete mode 100644 src/content/chapter5_advanced_features/lesson00_use/en.html (limited to 'src/content/chapter5_advanced_features/lesson00_use') diff --git a/src/content/chapter5_advanced_features/lesson00_use/code.gleam b/src/content/chapter5_advanced_features/lesson00_use/code.gleam deleted file mode 100644 index e7b435b..0000000 --- a/src/content/chapter5_advanced_features/lesson00_use/code.gleam +++ /dev/null @@ -1,38 +0,0 @@ -import gleam/io -import gleam/result - -pub fn main() { - io.debug(without_use()) - io.debug(with_use()) -} - -pub fn without_use() { - result.try(get_username(), fn(username) { - result.try(get_password(), fn(password) { - result.map(log_in(username, password), fn(greeting) { - greeting <> ", " <> username - }) - }) - }) -} - -pub fn with_use() { - use username <- result.try(get_username()) - use password <- result.try(get_password()) - use greeting <- result.map(log_in(username, password)) - greeting <> ", " <> username -} - -// Here are some pretend functions for this example: - -fn get_username() { - Ok("alice") -} - -fn get_password() { - Ok("hunter2") -} - -fn log_in(_username: String, _password: String) { - Ok("Welcome") -} diff --git a/src/content/chapter5_advanced_features/lesson00_use/en.html b/src/content/chapter5_advanced_features/lesson00_use/en.html deleted file mode 100644 index b8e2641..0000000 --- a/src/content/chapter5_advanced_features/lesson00_use/en.html +++ /dev/null @@ -1,31 +0,0 @@ -

- Gleam lacks exceptions, macros, type classes, early returns, and a variety of - other features, instead going all-in with just first-class-functions and - pattern matching. This makes Gleam code easier to understand, but it can - sometimes result in excessive indentation. -

-

- Gleam's use expression helps out here by enabling us to write code that uses - callbacks in an unindented style, as shown in the code window. -

- -

- The higher order function being called goes on the right hand side of the - <- operator. It must take a callback function as its final - argument. -

-

- The argument names for the callback function go on the left hand side of the - <- operator. The function can take any number of arguments, - including zero. -

-

- All the remaining code in the enclosing {} block - becomes the body of the callback function. -

-

- This is a very capable and useful feature, but excessive application of - use may result in code that is unclear otherwise, especially to - beginners. Often using the regular function call syntax will result in more - approachable code! -

-- cgit v1.2.3