diff options
author | Louis Pilfold <louis@lpil.uk> | 2024-02-20 12:20:16 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2024-02-20 12:20:16 +0000 |
commit | 938f49fc7835501192ccc7db7c1ab3174f050b34 (patch) | |
tree | 3e515fa15b6812df9947df80b8c16afd20faa436 /src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks | |
parent | e7d45ec089262e8b6731ddf87e65a06f4de07841 (diff) | |
download | tour-938f49fc7835501192ccc7db7c1ab3174f050b34.tar.gz tour-938f49fc7835501192ccc7db7c1ab3174f050b34.zip |
Let assert
Diffstat (limited to 'src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks')
-rw-r--r-- | src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/code.gleam | 18 | ||||
-rw-r--r-- | src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/en.html | 13 |
2 files changed, 0 insertions, 31 deletions
diff --git a/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/code.gleam b/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/code.gleam deleted file mode 100644 index a97b8fc..0000000 --- a/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/code.gleam +++ /dev/null @@ -1,18 +0,0 @@ -import gleam/io - -@external(erlang, "lists", "reverse") -pub fn reverse_list(items: List(e)) -> List(e) { - tail_recursive_reverse(items, []) -} - -fn tail_recursive_reverse(items: List(e), reversed: List(e)) -> List(e) { - case items { - [] -> reversed - [first, ..rest] -> tail_recursive_reverse(rest, [first, ..reversed]) - } -} - -pub fn main() { - io.debug(reverse_list([1, 2, 3, 4, 5])) - io.debug(reverse_list(["a", "b", "c", "d", "e"])) -} diff --git a/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/en.html b/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/en.html deleted file mode 100644 index 243c7ea..0000000 --- a/src/content/chapter5_advanced_features/lesson06_external_gleam_fallbacks/en.html +++ /dev/null @@ -1,13 +0,0 @@ -<p> - It's possible for a function to have both a Gleam implementation and an - external implementation. If there exists an external implementation for the - currently compiled-for target then it will be used, otherwise the Gleam - implementation is used. -</p> -<p> - This may be useful if you have a function that can be implemented in Gleam, - but there is an optimised implementation that can be used for one target. For - example, the Erlang virtual machine has a built-in list reverse function that - is implemented in native code. The code here uses this implementation when - running on Erlang, as it is then available. -</p> |