From 4efb34bd728732101432843ed0bfbeb971272287 Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Thu, 21 Dec 2023 14:03:41 +0000 Subject: Add chapters --- lessons/src/lesson000_hello_world/code.gleam | 5 ----- lessons/src/lesson000_hello_world/text.html | 26 ---------------------- lessons/src/lesson001_basics/code.gleam | 7 ------ lessons/src/lesson001_basics/text.html | 17 -------------- .../src/lesson002_unqualified_imports/code.gleam | 10 --------- .../src/lesson002_unqualified_imports/text.html | 15 ------------- lessons/src/lesson003_type_checking/code.gleam | 7 ------ lessons/src/lesson003_type_checking/text.html | 19 ---------------- lessons/src/lesson004_ints/code.gleam | 25 --------------------- lessons/src/lesson004_ints/text.html | 17 -------------- lessons/src/lesson005_floats/code.gleam | 24 -------------------- lessons/src/lesson005_floats/text.html | 19 ---------------- lessons/src/lesson006_number_formats/code.gleam | 16 ------------- lessons/src/lesson006_number_formats/text.html | 13 ----------- lessons/src/lesson007_strings/code.gleam | 20 ----------------- lessons/src/lesson007_strings/text.html | 23 ------------------- lessons/src/lesson008_bools/code.gleam | 14 ------------ lessons/src/lesson008_bools/text.html | 17 -------------- lessons/src/lesson009_assignments/code.gleam | 17 -------------- lessons/src/lesson009_assignments/text.html | 8 ------- lessons/src/lesson010_discard_patterns/code.gleam | 4 ---- lessons/src/lesson010_discard_patterns/text.html | 10 --------- lessons/src/lesson011_type_annotations/code.gleam | 7 ------ lessons/src/lesson011_type_annotations/text.html | 15 ------------- lessons/src/lesson012_blocks/code.gleam | 13 ----------- lessons/src/lesson012_blocks/text.html | 23 ------------------- lessons/src/lesson013_functions/code.gleam | 13 ----------- lessons/src/lesson013_functions/text.html | 14 ------------ .../lesson014_higher_order_functions/code.gleam | 18 --------------- .../src/lesson014_higher_order_functions/text.html | 12 ---------- .../src/lesson015_anonymous_functions/code.gleam | 14 ------------ .../src/lesson015_anonymous_functions/text.html | 7 ------ lessons/src/lesson016_function_captures/code.gleam | 14 ------------ lessons/src/lesson016_function_captures/text.html | 11 --------- lessons/src/lesson017_generic_functions/code.gleam | 19 ---------------- lessons/src/lesson017_generic_functions/text.html | 25 --------------------- lessons/src/lesson018_pipelines/code.gleam | 19 ---------------- lessons/src/lesson018_pipelines/text.html | 25 --------------------- .../src/lesson019_labelled_arguments/code.gleam | 16 ------------- lessons/src/lesson019_labelled_arguments/text.html | 23 ------------------- lessons/src/lesson020_lists/code.gleam | 16 ------------- lessons/src/lesson020_lists/text.html | 19 ---------------- lessons/src/lesson021_list_functions/code.gleam | 15 ------------- lessons/src/lesson021_list_functions/text.html | 25 --------------------- lessons/src/lesson022_case_expressions/code.gleam | 10 --------- lessons/src/lesson022_case_expressions/text.html | 7 ------ lessons/src/lesson023_variable_patterns/code.gleam | 16 ------------- lessons/src/lesson023_variable_patterns/text.html | 17 -------------- lessons/src/lesson024_string_patterns/code.gleam | 14 ------------ lessons/src/lesson024_string_patterns/text.html | 9 -------- lessons/src/lesson025_list_patterns/code.gleam | 17 -------------- lessons/src/lesson025_list_patterns/text.html | 15 ------------- lessons/src/lesson026_list_recursion/code.gleam | 13 ----------- lessons/src/lesson026_list_recursion/text.html | 22 ------------------ lessons/src/lesson027_multiple_subjects/code.gleam | 17 -------------- lessons/src/lesson027_multiple_subjects/text.html | 13 ----------- .../src/lesson028_alternative_patterns/code.gleam | 14 ------------ .../src/lesson028_alternative_patterns/text.html | 17 -------------- lessons/src/lesson029_pattern_aliases/code.gleam | 15 ------------- lessons/src/lesson029_pattern_aliases/text.html | 7 ------ lessons/src/lesson030_tuples/code.gleam | 10 --------- lessons/src/lesson030_tuples/text.html | 20 ----------------- lessons/src/lesson031_custom_types/code.gleam | 22 ------------------ lessons/src/lesson031_custom_types/text.html | 9 -------- lessons/src/lesson032_records/code.gleam | 17 -------------- lessons/src/lesson032_records/text.html | 10 --------- lessons/src/lesson033_record_accessors/code.gleam | 15 ------------- lessons/src/lesson033_record_accessors/text.html | 18 --------------- lessons/src/lesson034_record_updates/code.gleam | 15 ------------- lessons/src/lesson034_record_updates/text.html | 12 ---------- lessons/src/lesson035_nil/code.gleam | 11 --------- lessons/src/lesson035_nil/text.html | 15 ------------- lessons/src/lesson036_bit_arrays/code.gleam | 13 ----------- lessons/src/lesson036_bit_arrays/text.html | 26 ---------------------- .../lesson099_documentation_comments/code.gleam | 19 ---------------- .../src/lesson099_documentation_comments/text.html | 16 ------------- 76 files changed, 1167 deletions(-) delete mode 100644 lessons/src/lesson000_hello_world/code.gleam delete mode 100644 lessons/src/lesson000_hello_world/text.html delete mode 100644 lessons/src/lesson001_basics/code.gleam delete mode 100644 lessons/src/lesson001_basics/text.html delete mode 100644 lessons/src/lesson002_unqualified_imports/code.gleam delete mode 100644 lessons/src/lesson002_unqualified_imports/text.html delete mode 100644 lessons/src/lesson003_type_checking/code.gleam delete mode 100644 lessons/src/lesson003_type_checking/text.html delete mode 100644 lessons/src/lesson004_ints/code.gleam delete mode 100644 lessons/src/lesson004_ints/text.html delete mode 100644 lessons/src/lesson005_floats/code.gleam delete mode 100644 lessons/src/lesson005_floats/text.html delete mode 100644 lessons/src/lesson006_number_formats/code.gleam delete mode 100644 lessons/src/lesson006_number_formats/text.html delete mode 100644 lessons/src/lesson007_strings/code.gleam delete mode 100644 lessons/src/lesson007_strings/text.html delete mode 100644 lessons/src/lesson008_bools/code.gleam delete mode 100644 lessons/src/lesson008_bools/text.html delete mode 100644 lessons/src/lesson009_assignments/code.gleam delete mode 100644 lessons/src/lesson009_assignments/text.html delete mode 100644 lessons/src/lesson010_discard_patterns/code.gleam delete mode 100644 lessons/src/lesson010_discard_patterns/text.html delete mode 100644 lessons/src/lesson011_type_annotations/code.gleam delete mode 100644 lessons/src/lesson011_type_annotations/text.html delete mode 100644 lessons/src/lesson012_blocks/code.gleam delete mode 100644 lessons/src/lesson012_blocks/text.html delete mode 100644 lessons/src/lesson013_functions/code.gleam delete mode 100644 lessons/src/lesson013_functions/text.html delete mode 100644 lessons/src/lesson014_higher_order_functions/code.gleam delete mode 100644 lessons/src/lesson014_higher_order_functions/text.html delete mode 100644 lessons/src/lesson015_anonymous_functions/code.gleam delete mode 100644 lessons/src/lesson015_anonymous_functions/text.html delete mode 100644 lessons/src/lesson016_function_captures/code.gleam delete mode 100644 lessons/src/lesson016_function_captures/text.html delete mode 100644 lessons/src/lesson017_generic_functions/code.gleam delete mode 100644 lessons/src/lesson017_generic_functions/text.html delete mode 100644 lessons/src/lesson018_pipelines/code.gleam delete mode 100644 lessons/src/lesson018_pipelines/text.html delete mode 100644 lessons/src/lesson019_labelled_arguments/code.gleam delete mode 100644 lessons/src/lesson019_labelled_arguments/text.html delete mode 100644 lessons/src/lesson020_lists/code.gleam delete mode 100644 lessons/src/lesson020_lists/text.html delete mode 100644 lessons/src/lesson021_list_functions/code.gleam delete mode 100644 lessons/src/lesson021_list_functions/text.html delete mode 100644 lessons/src/lesson022_case_expressions/code.gleam delete mode 100644 lessons/src/lesson022_case_expressions/text.html delete mode 100644 lessons/src/lesson023_variable_patterns/code.gleam delete mode 100644 lessons/src/lesson023_variable_patterns/text.html delete mode 100644 lessons/src/lesson024_string_patterns/code.gleam delete mode 100644 lessons/src/lesson024_string_patterns/text.html delete mode 100644 lessons/src/lesson025_list_patterns/code.gleam delete mode 100644 lessons/src/lesson025_list_patterns/text.html delete mode 100644 lessons/src/lesson026_list_recursion/code.gleam delete mode 100644 lessons/src/lesson026_list_recursion/text.html delete mode 100644 lessons/src/lesson027_multiple_subjects/code.gleam delete mode 100644 lessons/src/lesson027_multiple_subjects/text.html delete mode 100644 lessons/src/lesson028_alternative_patterns/code.gleam delete mode 100644 lessons/src/lesson028_alternative_patterns/text.html delete mode 100644 lessons/src/lesson029_pattern_aliases/code.gleam delete mode 100644 lessons/src/lesson029_pattern_aliases/text.html delete mode 100644 lessons/src/lesson030_tuples/code.gleam delete mode 100644 lessons/src/lesson030_tuples/text.html delete mode 100644 lessons/src/lesson031_custom_types/code.gleam delete mode 100644 lessons/src/lesson031_custom_types/text.html delete mode 100644 lessons/src/lesson032_records/code.gleam delete mode 100644 lessons/src/lesson032_records/text.html delete mode 100644 lessons/src/lesson033_record_accessors/code.gleam delete mode 100644 lessons/src/lesson033_record_accessors/text.html delete mode 100644 lessons/src/lesson034_record_updates/code.gleam delete mode 100644 lessons/src/lesson034_record_updates/text.html delete mode 100644 lessons/src/lesson035_nil/code.gleam delete mode 100644 lessons/src/lesson035_nil/text.html delete mode 100644 lessons/src/lesson036_bit_arrays/code.gleam delete mode 100644 lessons/src/lesson036_bit_arrays/text.html delete mode 100644 lessons/src/lesson099_documentation_comments/code.gleam delete mode 100644 lessons/src/lesson099_documentation_comments/text.html (limited to 'lessons/src') diff --git a/lessons/src/lesson000_hello_world/code.gleam b/lessons/src/lesson000_hello_world/code.gleam deleted file mode 100644 index 30530b2..0000000 --- a/lessons/src/lesson000_hello_world/code.gleam +++ /dev/null @@ -1,5 +0,0 @@ -import gleam/io - -pub fn main() { - io.println("Hello, Joe!") -} diff --git a/lessons/src/lesson000_hello_world/text.html b/lessons/src/lesson000_hello_world/text.html deleted file mode 100644 index cb41be9..0000000 --- a/lessons/src/lesson000_hello_world/text.html +++ /dev/null @@ -1,26 +0,0 @@ -

Hello, friend ๐Ÿ’ซ

-

- Welcome to Try Gleam! An interactive tour of the Gleam programming language. -

-

- It covers all aspects of the Gleam language, and assuming you have some - prior programming experience should teach you everything you need to write - real programs in Gleam. -

-

- The tour is interactive! The code shown is editable and will be compiled and - evaluated as you type. Anything you print using io.println or - io.debug will be shown in the bottom section, along with any - compile errors and warnings. To evaluate Gleam code the tour compiles Gleam to - JavaScript and runs it, all entirely within your browser window. -

-

- If at any point you get stuck or have a question do not hesitate to ask in - the Gleam Discord server. We're here - to help, and if you find something confusing then it's likely others will too, - and we want to know about it so we can improve the tour. -

-

- OK, let's go. Click "Next" to get started, or click "Index" to jump to a - specific topic. -

diff --git a/lessons/src/lesson001_basics/code.gleam b/lessons/src/lesson001_basics/code.gleam deleted file mode 100644 index 67cc6b4..0000000 --- a/lessons/src/lesson001_basics/code.gleam +++ /dev/null @@ -1,7 +0,0 @@ -// Import a Gleam module from the standard library -import gleam/io - -pub fn main() { - // Print to the console - io.println("Hello, Joe!") -} diff --git a/lessons/src/lesson001_basics/text.html b/lessons/src/lesson001_basics/text.html deleted file mode 100644 index 8e2033a..0000000 --- a/lessons/src/lesson001_basics/text.html +++ /dev/null @@ -1,17 +0,0 @@ -

- Here is a program that prints out the text "Hello, Joe!". -

-

- It does this by using the `println` function which has been imported from the - gleam/io - module, which is part of the Gleam standard library. -

-

- In a normal Gleam program this program would be run use the command - gleam run on the command line, but here in this tutorial the - program is automatically compiled and run as the code is edited. -

-

- Try changing the text being printed to Hello, Mike! and see what - happens. -

diff --git a/lessons/src/lesson002_unqualified_imports/code.gleam b/lessons/src/lesson002_unqualified_imports/code.gleam deleted file mode 100644 index 2708f25..0000000 --- a/lessons/src/lesson002_unqualified_imports/code.gleam +++ /dev/null @@ -1,10 +0,0 @@ -// Import the module and one of its functions -import gleam/io.{println} - -pub fn main() { - // Use the function in a qualified fashion - io.println("This is qualified") - - // Or an unqualified fashion - println("This is unqualified") -} diff --git a/lessons/src/lesson002_unqualified_imports/text.html b/lessons/src/lesson002_unqualified_imports/text.html deleted file mode 100644 index 8fda45e..0000000 --- a/lessons/src/lesson002_unqualified_imports/text.html +++ /dev/null @@ -1,15 +0,0 @@ -

- Normally functions from other modules are used in a qualified fashion, with - the module qualifier before function name. For example, - io.println("Hello!"). -

-

- It is also possible to specify a list of functions to import from a module in - an unqualified fashion, such as the println function in the code - editor. Because it has been imported like this it can be referred to as just - println. -

-

- Generally it is best to use qualified imports, as this makes it clear where - the function is defined, making the code easier to read. -

diff --git a/lessons/src/lesson003_type_checking/code.gleam b/lessons/src/lesson003_type_checking/code.gleam deleted file mode 100644 index e068f31..0000000 --- a/lessons/src/lesson003_type_checking/code.gleam +++ /dev/null @@ -1,7 +0,0 @@ -import gleam/io - -pub fn main() { - io.println("My lucky number is:") - // io.println(4) - // ๐Ÿ‘†๏ธ Uncomment this line -} diff --git a/lessons/src/lesson003_type_checking/text.html b/lessons/src/lesson003_type_checking/text.html deleted file mode 100644 index fadfe64..0000000 --- a/lessons/src/lesson003_type_checking/text.html +++ /dev/null @@ -1,19 +0,0 @@ -

- Gleam has a robust static type system that is help you as you write and edit - code, catching mistakes and showing you where to make changes. -

-

- Uncomment the line io.println(4) and see how a compile time error - is reported as the io.println function only works with strings, - not ints. -

-

- To fix the code change the code to call the io.debug - function instead, as it will print a value of any type. -

-

- Gleam has no null, no implicit conversions, no exceptions, and - always performs full type checking. If the code compiles you can be reasonably - confident it does not have any inconsistencies that may cause bugs or - crashes. -

diff --git a/lessons/src/lesson004_ints/code.gleam b/lessons/src/lesson004_ints/code.gleam deleted file mode 100644 index cb7991b..0000000 --- a/lessons/src/lesson004_ints/code.gleam +++ /dev/null @@ -1,25 +0,0 @@ -import gleam/io -import gleam/int - -pub fn main() { - // Int arithmetic - io.debug(1 + 1) - io.debug(5 - 1) - io.debug(5 / 2) - io.debug(3 * 3) - io.debug(5 % 2) - - // Int comparisons - io.debug(2 > 1) - io.debug(2 < 1) - io.debug(2 >= 1) - io.debug(2 <= 1) - - // Equality works for any type - io.debug(1 == 1) - io.debug(2 == 1) - - // Standard library int functions - io.debug(int.max(42, 77)) - io.debug(int.clamp(5, 10, 20)) -} diff --git a/lessons/src/lesson004_ints/text.html b/lessons/src/lesson004_ints/text.html deleted file mode 100644 index 252496a..0000000 --- a/lessons/src/lesson004_ints/text.html +++ /dev/null @@ -1,17 +0,0 @@ -

Gleam's Int type represents whole numbers.

-

- There are arithmetic and comparison operators for ints, as well as the - equality operator which works on all types. -

-

- When running on the Erlang virtual machine ints have no maximum and minimum - size. When running on JavaScript runtimes ints are represented using - JavaScript's 64 bit floating point numbers, -

-

- The - gleam/int - standard library module contains functions for working with ints. -

diff --git a/lessons/src/lesson005_floats/code.gleam b/lessons/src/lesson005_floats/code.gleam deleted file mode 100644 index 8c4e89a..0000000 --- a/lessons/src/lesson005_floats/code.gleam +++ /dev/null @@ -1,24 +0,0 @@ -import gleam/io -import gleam/float - -pub fn main() { - // Float arithmetic - io.debug(1.0 +. 1.5) - io.debug(5.0 -. 1.5) - io.debug(5.0 /. 2.5) - io.debug(3.0 *. 3.5) - - // Float comparisons - io.debug(2.2 >. 1.3) - io.debug(2.2 <. 1.3) - io.debug(2.2 >=. 1.3) - io.debug(2.2 <=. 1.3) - - // Equality works for any type - io.debug(1.1 == 1.1) - io.debug(2.1 == 1.2) - - // Standard library float functions - io.debug(float.max(2.0, 9.5)) - io.debug(float.ceiling(5.4)) -} diff --git a/lessons/src/lesson005_floats/text.html b/lessons/src/lesson005_floats/text.html deleted file mode 100644 index 497bb13..0000000 --- a/lessons/src/lesson005_floats/text.html +++ /dev/null @@ -1,19 +0,0 @@ -

- Gleam's Float type represents numbers that are not integers. -

-

- Unlike many languages Gleam does not have a `NaN` or `Infinity` float value. -

-

- Gleam's numerical operators are not overloaded, so there are dedictated - operators for working with floats. -

-

- Floats are represented as 64 bit floating point numbers on both Erlang and - JavaScript runtimes. -

-

- The gleam/float - standard library module contains functions for working with floats. -

- diff --git a/lessons/src/lesson006_number_formats/code.gleam b/lessons/src/lesson006_number_formats/code.gleam deleted file mode 100644 index 7307185..0000000 --- a/lessons/src/lesson006_number_formats/code.gleam +++ /dev/null @@ -1,16 +0,0 @@ -import gleam/io - -pub fn main() { - // Underscores - io.debug(1_000_000) - io.debug(10_000.01) - - // Binary, octal, and hex Int literals - io.debug(0b00001111) - io.debug(0o17) - io.debug(0xF) - - // Scientific notation Float literals - io.debug(7.0e7) - io.debug(3.0e-4) -} diff --git a/lessons/src/lesson006_number_formats/text.html b/lessons/src/lesson006_number_formats/text.html deleted file mode 100644 index 308219a..0000000 --- a/lessons/src/lesson006_number_formats/text.html +++ /dev/null @@ -1,13 +0,0 @@ -

- Underscores can be added to numbers for clarity. For example, - 1000000 can be tricky to read quickly, while - 1_000_000 can be easier. -

-

- Ints can be written in binary, octal, or hexadecimal formats using the - 0b, 0o, and 0x prefixes respectively. -

-

- Floats can be written in a scientific notation. -

- diff --git a/lessons/src/lesson007_strings/code.gleam b/lessons/src/lesson007_strings/code.gleam deleted file mode 100644 index c77163e..0000000 --- a/lessons/src/lesson007_strings/code.gleam +++ /dev/null @@ -1,20 +0,0 @@ -import gleam/io -import gleam/string - -pub fn main() { - // String literals - io.debug("๐Ÿ‘ฉโ€๐Ÿ’ป ใ“ใ‚“ใซใกใฏ Gleam ๐Ÿณ๏ธโ€๐ŸŒˆ") - io.debug( - "multi - line - string", - ) - io.debug("\u{1F600}") - - // String concatenation - io.debug("One " <> "Two") - - // String functions - io.debug(string.reverse("1 2 3 4 5")) - io.debug(string.append("abc", "def")) -} diff --git a/lessons/src/lesson007_strings/text.html b/lessons/src/lesson007_strings/text.html deleted file mode 100644 index 820f1b3..0000000 --- a/lessons/src/lesson007_strings/text.html +++ /dev/null @@ -1,23 +0,0 @@ -

- In Gleam Strings are written as text surrounded by double quotes, and - can span multiple lines and contain unicode characters. -

-

- The <> operator can be used to concatenate strings. -

-

- Several escape sequences are supported: -

- -

- The gleam/string - standard library module contains functions for working with strings. -

diff --git a/lessons/src/lesson008_bools/code.gleam b/lessons/src/lesson008_bools/code.gleam deleted file mode 100644 index e5c1d98..0000000 --- a/lessons/src/lesson008_bools/code.gleam +++ /dev/null @@ -1,14 +0,0 @@ -import gleam/io -import gleam/bool - -pub fn main() { - // Bool operators - io.debug(True && False) - io.debug(True && True) - io.debug(False || False) - io.debug(False || True) - - // Bool functions - io.debug(bool.to_string(True)) - io.debug(bool.to_int(False)) -} diff --git a/lessons/src/lesson008_bools/text.html b/lessons/src/lesson008_bools/text.html deleted file mode 100644 index 3f60743..0000000 --- a/lessons/src/lesson008_bools/text.html +++ /dev/null @@ -1,17 +0,0 @@ -

- A Bool is a either True or False. -

-

- The ||, &&, and ! operators can be used - to manipulate bools. -

-

- The || and && operators are short-circuiting, - meaning that if the left hand side of the operator is True for - || or False for && then the right hand - side of the operator will not be evaluated. -

-

- The gleam/bool - standard library module contains functions for working with bools. -

diff --git a/lessons/src/lesson009_assignments/code.gleam b/lessons/src/lesson009_assignments/code.gleam deleted file mode 100644 index a030e43..0000000 --- a/lessons/src/lesson009_assignments/code.gleam +++ /dev/null @@ -1,17 +0,0 @@ -import gleam/io - -pub fn main() { - let x = "Original" - io.debug(x) - - // Assign `y` to the value of `x` - let y = x - io.debug(y) - - // Assign `x` to a new value - let x = "New" - io.debug(x) - - // The `y` still refers to the original value - io.debug(y) -} diff --git a/lessons/src/lesson009_assignments/text.html b/lessons/src/lesson009_assignments/text.html deleted file mode 100644 index 6d535de..0000000 --- a/lessons/src/lesson009_assignments/text.html +++ /dev/null @@ -1,8 +0,0 @@ -

- A value can be assigned to a variable using let. -

-

- Variable names can be reused by later let bindings, but the values they - reference are immutable, so the values themselves are not changed or mutated - in any way. -

diff --git a/lessons/src/lesson010_discard_patterns/code.gleam b/lessons/src/lesson010_discard_patterns/code.gleam deleted file mode 100644 index fa2c0e3..0000000 --- a/lessons/src/lesson010_discard_patterns/code.gleam +++ /dev/null @@ -1,4 +0,0 @@ -pub fn main() { - // This variable is never used - let _score = 1000 -} diff --git a/lessons/src/lesson010_discard_patterns/text.html b/lessons/src/lesson010_discard_patterns/text.html deleted file mode 100644 index 46dc79b..0000000 --- a/lessons/src/lesson010_discard_patterns/text.html +++ /dev/null @@ -1,10 +0,0 @@ -

- If a variable is assigned but not used then Gleam will emit a warning. -

-

- If a variable is intended not to be use then the name can be prefixed with an - underscore, silencing the warning. -

-

- Try changing the variable name to score to see the warning. -

diff --git a/lessons/src/lesson011_type_annotations/code.gleam b/lessons/src/lesson011_type_annotations/code.gleam deleted file mode 100644 index 1299c2f..0000000 --- a/lessons/src/lesson011_type_annotations/code.gleam +++ /dev/null @@ -1,7 +0,0 @@ -pub fn main() { - let _name: String = "Gleam" - - let _is_cool: Bool = True - - let _version: Int = 1 -} diff --git a/lessons/src/lesson011_type_annotations/text.html b/lessons/src/lesson011_type_annotations/text.html deleted file mode 100644 index 8738a15..0000000 --- a/lessons/src/lesson011_type_annotations/text.html +++ /dev/null @@ -1,15 +0,0 @@ -

- Let assignments can be written with a type annotation after the name. -

-

- Type annotations may be useful for documentation purposes, but they do not - change how Gleam type checks the code beyond ensuring that the annotation is - correct. -

-

- Typically Gleam code will not have type annotations for assignments. -

-

- Try changing a type annotation to something incorrect to see the compile - error. -

diff --git a/lessons/src/lesson012_blocks/code.gleam b/lessons/src/lesson012_blocks/code.gleam deleted file mode 100644 index 31e4729..0000000 --- a/lessons/src/lesson012_blocks/code.gleam +++ /dev/null @@ -1,13 +0,0 @@ -import gleam/io - -pub fn main() { - let fahrenheit = { - let degrees = 64 - degrees - } - // io.debug(degrees) // <- This will not compile - - // Changing order of evaluation - let celsius = { fahrenheit - 32 } * 5 / 9 - io.debug(celsius) -} diff --git a/lessons/src/lesson012_blocks/text.html b/lessons/src/lesson012_blocks/text.html deleted file mode 100644 index bc82e39..0000000 --- a/lessons/src/lesson012_blocks/text.html +++ /dev/null @@ -1,23 +0,0 @@ -

- Blocks are one or more expressions grouped together with curly braces. Each - expression is evaluated in order and the value of the last expression is - returned. -

-

- Any variables assigned within the block can only be used within the block. -

-

- Try uncommenting io.debug(degrees) to see the compile error from - trying to use a variable that is not in scope. -

-

- Blocks can also be used to change the order of evaluation of binary operators - expressions. -

-

- * binds more tightly than + so the expression - 1 + 2 * 3 evaluates to 7. If the 1 + 2 should be - evaluated first to make the expression evaluate to 9 then the expression can be - wrapped in a block: { 1 + 2 } * 3. This is similar to grouping - with parentheses in some other languages. -

diff --git a/lessons/src/lesson013_functions/code.gleam b/lessons/src/lesson013_functions/code.gleam deleted file mode 100644 index 220e58d..0000000 --- a/lessons/src/lesson013_functions/code.gleam +++ /dev/null @@ -1,13 +0,0 @@ -import gleam/io - -pub fn main() { - io.debug(double(10)) -} - -fn double(a: Int) -> Int { - multiply(a, 2) -} - -fn multiply(a: Int, b: Int) -> Int { - a * b -} diff --git a/lessons/src/lesson013_functions/text.html b/lessons/src/lesson013_functions/text.html deleted file mode 100644 index 32d5bed..0000000 --- a/lessons/src/lesson013_functions/text.html +++ /dev/null @@ -1,14 +0,0 @@ -

- The fn keyword is used to define new functions. -

-

- The double and multiply functions are defined - without the pub keyword. This makes them private - functions, they can only be used within this module. If another module - attempted to use them it would result in a compiler error. -

-

- Like with assignments, type annotations are optional for function arguments - and return values. It is considered good practice to use type annotations for - functions, for clarity and to encourage intentional and thoughtful design. -

diff --git a/lessons/src/lesson014_higher_order_functions/code.gleam b/lessons/src/lesson014_higher_order_functions/code.gleam deleted file mode 100644 index e3fb3e7..0000000 --- a/lessons/src/lesson014_higher_order_functions/code.gleam +++ /dev/null @@ -1,18 +0,0 @@ -import gleam/io - -pub fn main() { - // Call a function with another function - io.debug(twice(1, add_one)) - - // Functions can be assigned to variables - let function = add_one - io.debug(function(100)) -} - -fn twice(argument: Int, function: fn(Int) -> Int) -> Int { - function(function(argument)) -} - -fn add_one(argument: Int) -> Int { - argument + 1 -} diff --git a/lessons/src/lesson014_higher_order_functions/text.html b/lessons/src/lesson014_higher_order_functions/text.html deleted file mode 100644 index 3343e4d..0000000 --- a/lessons/src/lesson014_higher_order_functions/text.html +++ /dev/null @@ -1,12 +0,0 @@ -

- In Gleam functions are values. They can be assigned to variables, passed to - other functions, and anything else you can do with values. -

-

- Here the function add_one is being passed as an argument to the - twice function. -

-

- Notice the fn keyword is also used to describe the type of the - function that twice takes as its second argument. -

diff --git a/lessons/src/lesson015_anonymous_functions/code.gleam b/lessons/src/lesson015_anonymous_functions/code.gleam deleted file mode 100644 index 2b037e0..0000000 --- a/lessons/src/lesson015_anonymous_functions/code.gleam +++ /dev/null @@ -1,14 +0,0 @@ -import gleam/io - -pub fn main() { - // Assign an anonymous function to a variable - let add_one = fn(a) { a + 1 } - io.debug(twice(1, add_one)) - - // Pass an anonymous function as an argument - io.debug(twice(1, fn(a) { a * 2 })) -} - -fn twice(argument: Int, function: fn(Int) -> Int) -> Int { - function(function(argument)) -} diff --git a/lessons/src/lesson015_anonymous_functions/text.html b/lessons/src/lesson015_anonymous_functions/text.html deleted file mode 100644 index f7bea3f..0000000 --- a/lessons/src/lesson015_anonymous_functions/text.html +++ /dev/null @@ -1,7 +0,0 @@ -

- As well as module-level named functions, Gleam has anonymous function - literals. -

-

- Anonymous functions can be used interchangeably with named functions. -

diff --git a/lessons/src/lesson016_function_captures/code.gleam b/lessons/src/lesson016_function_captures/code.gleam deleted file mode 100644 index 35f3412..0000000 --- a/lessons/src/lesson016_function_captures/code.gleam +++ /dev/null @@ -1,14 +0,0 @@ -import gleam/io - -pub fn main() { - // These two statements are equivalent - let add_one_v1 = fn(x) { add(1, x) } - let add_one_v2 = add(1, _) - - io.debug(add_one_v1(10)) - io.debug(add_one_v2(10)) -} - -fn add(a: Int, b: Int) -> Int { - a + b -} diff --git a/lessons/src/lesson016_function_captures/text.html b/lessons/src/lesson016_function_captures/text.html deleted file mode 100644 index afa87a3..0000000 --- a/lessons/src/lesson016_function_captures/text.html +++ /dev/null @@ -1,11 +0,0 @@ -

- Gleam has a shorthand syntax for creating anonymous functions that take one - argument and immediately call another function with that argument: the - function capture syntax. -

-

- The anonymous function fn(a) { some_function(..., a, ...) } can - be written as some_function(..., _, ...), with any number of - other arguments passed to the inner function. The underscore _ is - a placeholder for the final argument. -

diff --git a/lessons/src/lesson017_generic_functions/code.gleam b/lessons/src/lesson017_generic_functions/code.gleam deleted file mode 100644 index e232bf8..0000000 --- a/lessons/src/lesson017_generic_functions/code.gleam +++ /dev/null @@ -1,19 +0,0 @@ -import gleam/io - -pub fn main() { - let add_one = fn(x) { x + 1 } - let exclaim = fn(x) { x <> "!" } - - // Invalid, Int and String are not the same type - // twice(10, exclaim) - - // Here the type variable is replaced by the type Int - io.debug(twice(10, add_one)) - - // Here the type variable is replaced by the type String - io.debug(twice("Hello", exclaim)) -} - -fn twice(argument: value, function: fn(value) -> value) -> value { - function(function(argument)) -} diff --git a/lessons/src/lesson017_generic_functions/text.html b/lessons/src/lesson017_generic_functions/text.html deleted file mode 100644 index 1369c93..0000000 --- a/lessons/src/lesson017_generic_functions/text.html +++ /dev/null @@ -1,25 +0,0 @@ -

- Up until now each function has accepted precisely one type for each of its - arguments. -

-

- The twice function for example only worked with functions that - would take and return ints. This is overly restrictive, it should be possible - to use this function with any type, so long as the function and the initial - value are compatible. -

-

- To enable this Gleam support generics, also known as parametric - polymorphism. -

-

- This works by instead of specifying a concrete type, a type variable is used - which stands in for whatever specific type is being used when the function is - called. These type variable are written with a lowercase name. -

-

- Type variables are not like an any type, they get replaced with a - specific type each time the function is called. Try uncommenting - twice(10, exclaim) to see the compiler error from trying to use a - type variable as an int and a string at the same time. -

diff --git a/lessons/src/lesson018_pipelines/code.gleam b/lessons/src/lesson018_pipelines/code.gleam deleted file mode 100644 index ec9b805..0000000 --- a/lessons/src/lesson018_pipelines/code.gleam +++ /dev/null @@ -1,19 +0,0 @@ -import gleam/io -import gleam/string - -pub fn main() { - // Without the pipe operator - io.debug(string.drop_left(string.drop_right("Hello, Joe!", 1), 7)) - - // With the pipe operator - "Hello, Mike!" - |> string.drop_right(1) - |> string.drop_left(7) - |> io.debug - - // Changing order with function capturing - "1" - |> string.append("2") - |> string.append("3", _) - |> io.debug -} diff --git a/lessons/src/lesson018_pipelines/text.html b/lessons/src/lesson018_pipelines/text.html deleted file mode 100644 index 783ade9..0000000 --- a/lessons/src/lesson018_pipelines/text.html +++ /dev/null @@ -1,25 +0,0 @@ -

- It's common to want to call a series of functions, passing the result of one - to the next. With the regular function call syntax this can be a little - difficult to read as you have to read the code from the inside out. -

-

- Gleam's pipe operator |> helps with this problem by allowing you - to write code top-to-bottom. -

-

- The pipe operator takes the result of the expression on its left and passes it - as an argument to the function on its right. -

-

- It will first check to see if the left-hand value could be used as the first - argument to the call. For example, a |> b(1, 2) would become - b(a, 1, 2). If not, it falls back to calling the result of the - right-hand side as a function, e.g., b(1, 2)(a) -

-

- Gleam code is typically written with the "subject" of the function as the - first argument, to make it easier to pipe. If you wish to pipe to a different - position then a function capture can be used to insert the argument to the - desired position. -

diff --git a/lessons/src/lesson019_labelled_arguments/code.gleam b/lessons/src/lesson019_labelled_arguments/code.gleam deleted file mode 100644 index 25bb8c1..0000000 --- a/lessons/src/lesson019_labelled_arguments/code.gleam +++ /dev/null @@ -1,16 +0,0 @@ -import gleam/io - -pub fn main() { - // Without using labels - io.debug(calculate(1, 2, 3)) - - // Using the labels - io.debug(calculate(1, add: 2, multiply: 3)) - - // Using the labels in a different order - io.debug(calculate(1, multiply: 3, add: 2)) -} - -fn calculate(value: Int, add addend: Int, multiply multiplier: Int) { - value * multiplier + addend -} diff --git a/lessons/src/lesson019_labelled_arguments/text.html b/lessons/src/lesson019_labelled_arguments/text.html deleted file mode 100644 index b1d771c..0000000 --- a/lessons/src/lesson019_labelled_arguments/text.html +++ /dev/null @@ -1,23 +0,0 @@ -

- When functions take several arguments it can be difficult to remember what the - arguments are, and what order they are expected in. -

-

- To help with this Gleam supports labelled arguments, where function arguments - are given an external label in addition to their internal name. These labels - are written before the argument name in the function definition. -

-

- When labelled arguments are used the order of the arguments does not matter, - but all unlabelled arguments must come before labelled arguments. -

-

- There is no performance cost to using labelled arguments, it does not allocate - a dictionary or perform any other runtime work. -

-

- Labels are optional when calling a function, it is up to the programmer to - decide what is clearest in their code. -

- - diff --git a/lessons/src/lesson020_lists/code.gleam b/lessons/src/lesson020_lists/code.gleam deleted file mode 100644 index 646ad6e..0000000 --- a/lessons/src/lesson020_lists/code.gleam +++ /dev/null @@ -1,16 +0,0 @@ -import gleam/io - -pub fn main() { - let ints = [1, 2, 3] - - io.debug(ints) - - // Immutably prepend - io.debug([-1, 0, ..ints]) - - // Uncomment this to see the error - // io.debug(["zero", ..ints]) - - // The original lists are unchanged - io.debug(ints) -} diff --git a/lessons/src/lesson020_lists/text.html b/lessons/src/lesson020_lists/text.html deleted file mode 100644 index dd07cd7..0000000 --- a/lessons/src/lesson020_lists/text.html +++ /dev/null @@ -1,19 +0,0 @@ -

- Lists are ordered collections of values. -

-

- List is a generic type, having a type parameter - for the type of values it contains. A list of ints has the type - List(Int), and a list of strings has the type - List(String). -

-

- Lists are immutable single-linked lists, meaning they are very efficient to - add and remove elements from the front of the list. -

-

- Counting the length of a list or getting elements from other positions in the - list is expensive and rarely done. It is rare to write algorithms that index - into sequences in Gleam, but but when they are written a list is not the right - choice of data structure. -

diff --git a/lessons/src/lesson021_list_functions/code.gleam b/lessons/src/lesson021_list_functions/code.gleam deleted file mode 100644 index 8cd4ced..0000000 --- a/lessons/src/lesson021_list_functions/code.gleam +++ /dev/null @@ -1,15 +0,0 @@ -import gleam/io -import gleam/list - -pub fn main() { - let ints = [0, 1, 2, 3, 4, 5] - - let doubled = list.map(ints, fn(x) { x * 2 }) - io.debug(doubled) - - let even = list.filter(ints, fn(x) { x % 2 == 0 }) - io.debug(even) - - let total = list.fold(ints, from: 0, with: fn(count, e) { count + e }) - io.debug(total) -} diff --git a/lessons/src/lesson021_list_functions/text.html b/lessons/src/lesson021_list_functions/text.html deleted file mode 100644 index e143654..0000000 --- a/lessons/src/lesson021_list_functions/text.html +++ /dev/null @@ -1,25 +0,0 @@ -

- The gleam/list - standard library module contains functions for working with lists. A Gleam - program will likely make heavy use of this module. -

- -

- map - makes a new list by running a function on each element in a list. -

-

- filter - makes a new list containing only the elements for which a function returns - true. -

-

- fold - combines all the elements in a list into a single value by running a function - left-to-right on each element, passing the result of the previous call to the - next call. -

-

- It's worth getting familiar with all the functions in this module when writing - Gleam code. -

diff --git a/lessons/src/lesson022_case_expressions/code.gleam b/lessons/src/lesson022_case_expressions/code.gleam deleted file mode 100644 index 33c0290..0000000 --- a/lessons/src/lesson022_case_expressions/code.gleam +++ /dev/null @@ -1,10 +0,0 @@ -import gleam/io -import gleam/int - -pub fn main() { - let result = case int.random(0, 5) { - 0 -> "It's zero!" - other -> "It's " <> int.to_string(other) - } - io.debug(result) -} diff --git a/lessons/src/lesson022_case_expressions/text.html b/lessons/src/lesson022_case_expressions/text.html deleted file mode 100644 index 7e9ac11..0000000 --- a/lessons/src/lesson022_case_expressions/text.html +++ /dev/null @@ -1,7 +0,0 @@ -

- Patterns in case expressions can also assign variables. -

-

- When a variable name is used in a pattern the value that is matched against is - assigned to that name, and can be used in the body of that clause. -

diff --git a/lessons/src/lesson023_variable_patterns/code.gleam b/lessons/src/lesson023_variable_patterns/code.gleam deleted file mode 100644 index 78eb050..0000000 --- a/lessons/src/lesson023_variable_patterns/code.gleam +++ /dev/null @@ -1,16 +0,0 @@ -import gleam/io -import gleam/int - -pub fn main() { - let x = int.random(0, 5) - io.debug(x) - - let result = case x { - // Match specific values - 0 -> "Zero" - 1 -> "One" - // Match any other value - _ -> "Other" - } - io.debug(result) -} diff --git a/lessons/src/lesson023_variable_patterns/text.html b/lessons/src/lesson023_variable_patterns/text.html deleted file mode 100644 index 8154979..0000000 --- a/lessons/src/lesson023_variable_patterns/text.html +++ /dev/null @@ -1,17 +0,0 @@ -

- The case expression is the most common kind of flow control in Gleam code. It - is similar to `switch` in some other languages, but more powerful than most. -

-

- It allows the programmer to say "if the data has this shape then run this - code", a process called called pattern matching. -

-

- Gleam performs exhaustiveness checking to ensure that the patterns in - a case expression cover all possible values. With this you can have confidence - that your logic is up-to-date for the design of the data you are working with. -

-

- Try commenting out patterns or adding new redundant ones, and see what - problems the compiler reports. -

diff --git a/lessons/src/lesson024_string_patterns/code.gleam b/lessons/src/lesson024_string_patterns/code.gleam deleted file mode 100644 index d1441a0..0000000 --- a/lessons/src/lesson024_string_patterns/code.gleam +++ /dev/null @@ -1,14 +0,0 @@ -import gleam/io - -pub fn main() { - io.debug(get_name("Hello, Joe")) - io.debug(get_name("Hello, Mike")) - io.debug(get_name("System still working?")) -} - -fn get_name(x: String) -> String { - case x { - "Hello, " <> name -> name - _ -> "Unknown" - } -} diff --git a/lessons/src/lesson024_string_patterns/text.html b/lessons/src/lesson024_string_patterns/text.html deleted file mode 100644 index 0dd3274..0000000 --- a/lessons/src/lesson024_string_patterns/text.html +++ /dev/null @@ -1,9 +0,0 @@ -

- When pattern matching on strings the <> operator can be - used to match on strings with a specific prefix. -

-

- The pattern "hello " <> name matches any string that starts with - "hello " and asigns the rest of the string to the variable - name. -

diff --git a/lessons/src/lesson025_list_patterns/code.gleam b/lessons/src/lesson025_list_patterns/code.gleam deleted file mode 100644 index a5619aa..0000000 --- a/lessons/src/lesson025_list_patterns/code.gleam +++ /dev/null @@ -1,17 +0,0 @@ -import gleam/io -import gleam/int -import gleam/list - -pub fn main() { - let x = list.repeat(int.random(0, 5), times: int.random(0, 3)) - io.debug(x) - - let result = case x { - [] -> "Empty list" - [1] -> "List of just 1" - [4, ..] -> "List starting with 4" - [_, _] -> "List of 2 elements" - _ -> "Some other list" - } - io.debug(result) -} diff --git a/lessons/src/lesson025_list_patterns/text.html b/lessons/src/lesson025_list_patterns/text.html deleted file mode 100644 index de55eef..0000000 --- a/lessons/src/lesson025_list_patterns/text.html +++ /dev/null @@ -1,15 +0,0 @@ -

- Lists and the values they contain can be pattern matched on in case - expressions. -

-

- List patterns match on specific lengths of lists. The pattern [] - matches an empty list, and the pattern [_] matches a list with - one element. They will not match on lists with other lengths. -

-

- The spread pattern .. can be used to match the rest of the list. - The pattern [1, ..] matches any list that starts with - 1. The pattern [_, _, ..] matches any list that has - at least two elements. -

diff --git a/lessons/src/lesson026_list_recursion/code.gleam b/lessons/src/lesson026_list_recursion/code.gleam deleted file mode 100644 index 370675a..0000000 --- a/lessons/src/lesson026_list_recursion/code.gleam +++ /dev/null @@ -1,13 +0,0 @@ -import gleam/io - -pub fn main() { - let sum = sum_list([18, 56, 35, 85, 91], 0) - io.debug(sum) -} - -fn sum_list(list: List(Int), total: Int) -> Int { - case list { - [first, ..rest] -> sum_list(rest, total + first) - [] -> total - } -} diff --git a/lessons/src/lesson026_list_recursion/text.html b/lessons/src/lesson026_list_recursion/text.html deleted file mode 100644 index 7f2351d..0000000 --- a/lessons/src/lesson026_list_recursion/text.html +++ /dev/null @@ -1,22 +0,0 @@ -

- Most commonly functions in the - gleam/list - module are used to iterate across a list, but at times you may prefer - to work with the list directly. -

-

- Gleam doesn't have a looping syntax, instead iteration is done through - recursion and pattern matching. -

-

- The [first, ..rest] pattern matches on a list with at least one - element, assigning the first element to the variable first and - the rest of the list to the variable rest. - By using this pattern and a pattern for the empty list [] a - function can run code on each element of a list until the end is reached. -

-

- This code sums a list by recursing over the list and adding each int to a - total argument, returning it when the end is reached. -

- diff --git a/lessons/src/lesson027_multiple_subjects/code.gleam b/lessons/src/lesson027_multiple_subjects/code.gleam deleted file mode 100644 index d7aa34a..0000000 --- a/lessons/src/lesson027_multiple_subjects/code.gleam +++ /dev/null @@ -1,17 +0,0 @@ -import gleam/io -import gleam/int - -pub fn main() { - let x = int.random(2) - let y = int.random(2) - io.debug(x) - io.debug(y) - - let result = case x, y { - 0, 0 -> "Both are zero" - 0, _ -> "First is zero" - _, 0 -> "Second is zero" - _, _ -> "Neither are zero" - } - io.debug(result) -} diff --git a/lessons/src/lesson027_multiple_subjects/text.html b/lessons/src/lesson027_multiple_subjects/text.html deleted file mode 100644 index 26a7ea3..0000000 --- a/lessons/src/lesson027_multiple_subjects/text.html +++ /dev/null @@ -1,13 +0,0 @@ -

- Sometimes it is useful to pattern match on multiple values at the same time in - one case experession. -

-

- To do this you can give multiple subjects and multiple patterns, separated - commas. -

-

- When matching on multiple subjects there must be the same number of patterns - as there are subjects. Try removing one of the _, sub-patterns to - see the compile time error that is returned. -

diff --git a/lessons/src/lesson028_alternative_patterns/code.gleam b/lessons/src/lesson028_alternative_patterns/code.gleam deleted file mode 100644 index 06a6562..0000000 --- a/lessons/src/lesson028_alternative_patterns/code.gleam +++ /dev/null @@ -1,14 +0,0 @@ -import gleam/io -import gleam/int - -pub fn main() { - let number = int.random(10) - io.debug(number) - - let result = case number { - 2 | 4 | 6 | 8 -> "This is an even number" - 1 | 3 | 5 | 7 -> "This is an odd number" - _ -> "I'm not sure" - } - io.debug(result) -} diff --git a/lessons/src/lesson028_alternative_patterns/text.html b/lessons/src/lesson028_alternative_patterns/text.html deleted file mode 100644 index 10ad731..0000000 --- a/lessons/src/lesson028_alternative_patterns/text.html +++ /dev/null @@ -1,17 +0,0 @@ -

- Alternative patterns can be given for a case clause using the - | operator. If any of the patterns match then the clause matches. -

-

- When matching on multiple subjects there must be the same number of patterns - as there are subjects. Try removing one of the _, sub-patterns to - see the compile time error that is returned. -

-

- If a pattern defines a variable then all of the alternative patterns for that - clause must also define a variable with the same name and same type. -

-

- Currently it is not possible to have nested alternative patterns, so the - pattern [1 | 2 | 3] is not valid. -

diff --git a/lessons/src/lesson029_pattern_aliases/code.gleam b/lessons/src/lesson029_pattern_aliases/code.gleam deleted file mode 100644 index ee40a26..0000000 --- a/lessons/src/lesson029_pattern_aliases/code.gleam +++ /dev/null @@ -1,15 +0,0 @@ -import gleam/io - -pub fn main() { - io.debug(get_first_non_empty([[], [1, 2, 3], [4, 5]])) - io.debug(get_first_non_empty([[1, 2], [3, 4, 5], []])) - io.debug(get_first_non_empty([[], [], []])) -} - -fn get_first_non_empty(lists: List(List(t))) -> List(t) { - case lists { - [[_, ..] as first, ..] -> first - [_, ..rest] -> get_first_non_empty(rest) - [] -> [] - } -} diff --git a/lessons/src/lesson029_pattern_aliases/text.html b/lessons/src/lesson029_pattern_aliases/text.html deleted file mode 100644 index b737eb8..0000000 --- a/lessons/src/lesson029_pattern_aliases/text.html +++ /dev/null @@ -1,7 +0,0 @@ -

- The as operator can be used to assign sub patterns to variables. -

-

- The pattern [_, ..] as it will match any non-empty list and - assign that list to the variable it. -

diff --git a/lessons/src/lesson030_tuples/code.gleam b/lessons/src/lesson030_tuples/code.gleam deleted file mode 100644 index d5c6313..0000000 --- a/lessons/src/lesson030_tuples/code.gleam +++ /dev/null @@ -1,10 +0,0 @@ -import gleam/io - -pub fn main() { - let triple = #(1, 2.2, "three") - io.debug(triple) - - let #(a, _, _) = triple - io.debug(a) - io.debug(triple.1) -} diff --git a/lessons/src/lesson030_tuples/text.html b/lessons/src/lesson030_tuples/text.html deleted file mode 100644 index f121a9d..0000000 --- a/lessons/src/lesson030_tuples/text.html +++ /dev/null @@ -1,20 +0,0 @@ -

- Lists are good for when we want a collection of one type, but sometimes we - want to combine multiple values of different types. In this case tuples are a - quick and convenient option. -

-

- The tuple access syntax can be used to get elements from a tuple without - pattern matching. some_tuple.0 gets the first element, - some_tuple.1 gets the second element, etc. -

-

- Tuples are generic types, they have type parameters for the types they - contain. #(1, "Hi!") has the type #(Int, String), - and #(1.4, 10, 48) has the type #(Float, Int, Int). -

-

- Tuples are most commonly used to return 2 or 3 values from a function. Other - times it is often is clearer to use a custom type, which we will - cover next. -

diff --git a/lessons/src/lesson031_custom_types/code.gleam b/lessons/src/lesson031_custom_types/code.gleam deleted file mode 100644 index 35629bf..0000000 --- a/lessons/src/lesson031_custom_types/code.gleam +++ /dev/null @@ -1,22 +0,0 @@ -import gleam/io - -pub type Season { - Spring - Summer - Autumn - Winter -} - -pub fn main() { - io.debug(weather(Spring)) - io.debug(weather(Autumn)) -} - -fn weather(season: Season) -> String { - case season { - Spring -> "Mild" - Summer -> "Hot" - Autumn -> "Windy" - Winter -> "Cold" - } -} diff --git a/lessons/src/lesson031_custom_types/text.html b/lessons/src/lesson031_custom_types/text.html deleted file mode 100644 index dad6d12..0000000 --- a/lessons/src/lesson031_custom_types/text.html +++ /dev/null @@ -1,9 +0,0 @@ -

- Gleam has a few built in types such as Int, String, - but custom types allow the creation of entirely new types. -

-

- A custom type is defined with the type keyword followed by a - constructor for each variant of the type. -

-

Custom type variants can be pattern matched on using a case expression.

diff --git a/lessons/src/lesson032_records/code.gleam b/lessons/src/lesson032_records/code.gleam deleted file mode 100644 index bd6da3c..0000000 --- a/lessons/src/lesson032_records/code.gleam +++ /dev/null @@ -1,17 +0,0 @@ -import gleam/io - -pub type SchoolPerson { - Teacher(name: String, subject: String) - Student(String) -} - -pub fn main() { - let teacher1 = Teacher("Mr Schofield", "Physics") - let teacher2 = Teacher(name: "Miss Percy", subject: "Physics") - let student1 = Student("Koushiar") - let student2 = Student("Naomi") - let student3 = Student("Shaheer") - - let school = [teacher1, teacher2, student1, student2, student3] - io.debug(school) -} diff --git a/lessons/src/lesson032_records/text.html b/lessons/src/lesson032_records/text.html deleted file mode 100644 index f515ccd..0000000 --- a/lessons/src/lesson032_records/text.html +++ /dev/null @@ -1,10 +0,0 @@ -

Variants of a record can hold other data within them.

-

- These fields can be given labels, and like function argument labels they can - be optionally used when calling the record constructor. Typically labels will - be used for variants that define them. -

-

- It is common to have a custom type with one variant that holds data, this is - the Gleam equivalent of a struct or object in other languages. -

diff --git a/lessons/src/lesson033_record_accessors/code.gleam b/lessons/src/lesson033_record_accessors/code.gleam deleted file mode 100644 index 63ca721..0000000 --- a/lessons/src/lesson033_record_accessors/code.gleam +++ /dev/null @@ -1,15 +0,0 @@ -import gleam/io - -pub type SchoolPerson { - Teacher(name: String, subject: String) - Student(name: String) -} - -pub fn main() { - let teacher = Teacher("Mr Schofield", "Physics") - let student = Student("Koushiar") - - io.debug(teacher.name) - io.debug(student.name) - // io.debug(teacher.subject) -} diff --git a/lessons/src/lesson033_record_accessors/text.html b/lessons/src/lesson033_record_accessors/text.html deleted file mode 100644 index e8bbbc2..0000000 --- a/lessons/src/lesson033_record_accessors/text.html +++ /dev/null @@ -1,18 +0,0 @@ -

- The record accessor syntax record.field_label can be used to get - contained values from a custom type record. -

-

- The accessor syntax can only be used for fields that are in the same position - and have the same type for all variants of the custom type. -

-

- The name field is in the first position and has type - String for all variants, so it can be accessed. -

-

- The subject field is absent on the Student variant, - so it cannot be used on any variant of type SchoolPerson. - Uncomment the teacher.subject line to see the compile error from - trying to use this accessor. -

diff --git a/lessons/src/lesson034_record_updates/code.gleam b/lessons/src/lesson034_record_updates/code.gleam deleted file mode 100644 index ed7b45b..0000000 --- a/lessons/src/lesson034_record_updates/code.gleam +++ /dev/null @@ -1,15 +0,0 @@ -import gleam/io - -pub type SchoolPerson { - Teacher(name: String, subject: String, floor: Int, room: Int) -} - -pub fn main() { - let teacher1 = Teacher(name: "Mr Dodd", subject: "ICT", floor: 2, room: 2) - - // Use the update syntax - let teacher2 = Teacher(..teacher1, subject: "PE", room: 6) - - io.debug(teacher1) - io.debug(teacher2) -} diff --git a/lessons/src/lesson034_record_updates/text.html b/lessons/src/lesson034_record_updates/text.html deleted file mode 100644 index f23d7cd..0000000 --- a/lessons/src/lesson034_record_updates/text.html +++ /dev/null @@ -1,12 +0,0 @@ -

- The record update syntax can be used to create a new record from an existing - one of the same type, but with some fields changed. -

-

- The accessor syntax can only be used for fields that are in the same position - and have the same type for all variants of the custom type. -

-

- Gleam is an immutable language, so using the record update syntax does not - mutate or otherwise change the original record. -

diff --git a/lessons/src/lesson035_nil/code.gleam b/lessons/src/lesson035_nil/code.gleam deleted file mode 100644 index c28080b..0000000 --- a/lessons/src/lesson035_nil/code.gleam +++ /dev/null @@ -1,11 +0,0 @@ -import gleam/io - -pub fn main() { - let x = Nil - io.debug(x) - - // let y: List(String) = Nil - - let result = io.println("Hello!") - io.debug(result == Nil) -} diff --git a/lessons/src/lesson035_nil/text.html b/lessons/src/lesson035_nil/text.html deleted file mode 100644 index 3416643..0000000 --- a/lessons/src/lesson035_nil/text.html +++ /dev/null @@ -1,15 +0,0 @@ -

- Nil is Gleam's unit type. It is a value that is returned by - functions that have nothing else to return, as all functions much return - something. -

-

- Nil is not a valid value of any other types, that is values in - Gleam are not nullable. If the type of a value is Nil then it is - the value nil. If it is some other type then the value is not - Nil. -

-

- Uncomment the line that assigns Nil to a variable with an - incompatible type annotation to see the comile time error it produces. -

diff --git a/lessons/src/lesson036_bit_arrays/code.gleam b/lessons/src/lesson036_bit_arrays/code.gleam deleted file mode 100644 index dc772ca..0000000 --- a/lessons/src/lesson036_bit_arrays/code.gleam +++ /dev/null @@ -1,13 +0,0 @@ -import gleam/io - -pub fn main() { - // 8 bit int. In binary: 00000011 - io.debug(<<3>>) - io.debug(<<3>> == <<3:size(8)>>) - - // 16 bit int. In binary: 0001100000000011 - io.debug(<<6147:size(16)>>) - - // A bit array of UTF8 data - io.debug(<<"Hello, Joe!":utf8>>) -} diff --git a/lessons/src/lesson036_bit_arrays/text.html b/lessons/src/lesson036_bit_arrays/text.html deleted file mode 100644 index 3214db1..0000000 --- a/lessons/src/lesson036_bit_arrays/text.html +++ /dev/null @@ -1,26 +0,0 @@ -

- Bit arrays represent a sequence of 1s and 0s, and are a convenient syntax for - constructing and manipulating binary data. -

-

- Each segment of a bit array can be given options to specify the representation - used for that segment. -

- -

- Bit arrays have limited support when compiling to JavaScript, not all options - can be used. Full bit array support will be implemented in future. -

diff --git a/lessons/src/lesson099_documentation_comments/code.gleam b/lessons/src/lesson099_documentation_comments/code.gleam deleted file mode 100644 index a84dce6..0000000 --- a/lessons/src/lesson099_documentation_comments/code.gleam +++ /dev/null @@ -1,19 +0,0 @@ -//// A module containing some unusual functions and types. - -/// A type where the value can never be constructed. -/// Can you work out why? -pub type Never { - Never(Never) -} - -/// Call a function twice with an initial value. -/// -pub fn twice(argument: value, function: fn(value) -> value) -> value { - function(function(argument)) -} - -/// Call a function three times with an initial value. -/// -pub fn thrice(argument: value, function: fn(value) -> value) -> value { - function(function(function(argument))) -} diff --git a/lessons/src/lesson099_documentation_comments/text.html b/lessons/src/lesson099_documentation_comments/text.html deleted file mode 100644 index c27bac6..0000000 --- a/lessons/src/lesson099_documentation_comments/text.html +++ /dev/null @@ -1,16 +0,0 @@ -

- Documentation and comments are important tools for making your code easier to - work with and understand. -

-

- As well as regular // comments Gleam has /// and - //// comments which are used for attaching documentation to code. -

-

- /// is used for documenting types and functions, and should be - placed immediately before the type or function it is documenting. -

-

- //// is used for documenting modules, and should be placed - at the top of the module. -

-- cgit v1.2.3