-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
11 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
main = | ||
Path.fromStr "url.txt" | ||
|> storeEmail | ||
|> Task.onErr handleErr | ||
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" } | ||
|
||
import pf.Stdout | ||
|
||
storeEmail = \path -> | ||
url = File.readUtf8! path | ||
user = Http.get! url Json.utf8 | ||
dest = Path.fromStr "$(user.name).txt" | ||
File.writeUtf8! dest user.email | ||
Stdout.line! "Wrote email to $(Path.display dest)" | ||
factorial = \n -> | ||
if n == 1 then | ||
1 | ||
else | ||
n * factorial (n - 1) | ||
|
||
handleErr = \err -> | ||
when err is | ||
HttpErr url _ -> Stderr.line! "Error fetching URL $(url)" | ||
FileReadErr path _ -> Stderr.line! "Error reading from $(Path.display path)" | ||
FileWriteErr path _ -> Stderr.line! "Error writing to $(Path.display path)" | ||
main = | ||
result = factorial 5 | ||
Stdout.line! "factorial 5 = 1 * 2 * 3 * 4 * 5 = $(Num.toStr result)" |