diff options
author | Louis Pilfold <louis@lpil.uk> | 2024-01-18 17:47:12 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-01-18 17:47:12 +0000 |
commit | 3bfbe688f5a62e29835c7d3c4f282e7fff57949d (patch) | |
tree | 038cd1bf7a72949f7d68358ffd8af59d073ef70a /src/content/chapter5_advance_features/lesson00_use | |
parent | f92661980deac22b54e79cd44c25caba17910c95 (diff) | |
download | tour-3bfbe688f5a62e29835c7d3c4f282e7fff57949d.tar.gz tour-3bfbe688f5a62e29835c7d3c4f282e7fff57949d.zip |
Rename
Diffstat (limited to 'src/content/chapter5_advance_features/lesson00_use')
-rw-r--r-- | src/content/chapter5_advance_features/lesson00_use/code.gleam | 38 | ||||
-rw-r--r-- | src/content/chapter5_advance_features/lesson00_use/text.html | 31 |
2 files changed, 0 insertions, 69 deletions
diff --git a/src/content/chapter5_advance_features/lesson00_use/code.gleam b/src/content/chapter5_advance_features/lesson00_use/code.gleam deleted file mode 100644 index 37624ab..0000000 --- a/src/content/chapter5_advance_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_usename(), 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_usename()) - 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_usename() { - Ok("alice") -} - -fn get_password() { - Ok("hunter2") -} - -fn log_in(_username: String, _password: String) { - Ok("Welcome") -} diff --git a/src/content/chapter5_advance_features/lesson00_use/text.html b/src/content/chapter5_advance_features/lesson00_use/text.html deleted file mode 100644 index e295dda..0000000 --- a/src/content/chapter5_advance_features/lesson00_use/text.html +++ /dev/null @@ -1,31 +0,0 @@ -<p> - 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. -</p> -<p> - 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. -</p> - -<p> - The higher order function being called goes on the right hand side of the - <code><-</code> operator. It must take a callback function as its final - argument. -</p> -<p> - The argument names for the callback function go on the left hand side of the - <code><-</code> operator. The function can take any number of arguments, - including zero. -</p> -<p> - All the following code in the <code class="hljs">{}</code> block becomes the - body of the callback function. -</p> -<p> - This is a very capable and useful feature, but excessive application of - <code>use</code> may result in code that is unclear otherwise, especially to - beginners. Often using the regular function call syntax will result in more - approachable code! -</p> |