Skip to content

Commit

Permalink
remove examples/http-get-json.roc, update flake, fix builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewilliamboswell committed Jan 7, 2025
1 parent 07c3807 commit 89dc0fe
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 78 deletions.
27 changes: 0 additions & 27 deletions ci/expect_scripts/http-get-json.exp

This file was deleted.

2 changes: 1 addition & 1 deletion examples/dir.roc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ main! = \_args ->
|> try

# Check the contents of the directory
expect (Set.fromList paths_as_str) == (Set.fromList ["dirExampleA/b", "dirExampleA/child"])
expect (Set.from_list paths_as_str) == (Set.from_list ["dirExampleA/b", "dirExampleA/child"])

# Try to create a directory without a parent (should fail, ignore error)
when Dir.create! "dirExampleD/child" is
Expand Down
4 changes: 2 additions & 2 deletions examples/env-var.roc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ main! = \_args ->

# Env.decode! does not return the same type everywhere.
# The type is determined based on type inference.
# Here `Str.joinWith` forces the type that Env.decode! returns to be `List Str`
# Here `Str.join_with` forces the type that Env.decode! returns to be `List Str`
joined_letters =
Env.decode! "LETTERS"
|> Result.map \letters -> Str.joinWith letters " "
|> Result.map \letters -> Str.join_with letters " "
|> try

Stdout.line! "Your favorite letters are: $(joined_letters)"
2 changes: 1 addition & 1 deletion examples/file-mixed.roc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ task! = \{} ->

dir_entries = try Dir.list! cwd_str

dir_entries_tr = Str.joinWith (List.map dir_entries Path.display) "\n "
dir_entries_tr = Str.join_with (List.map dir_entries Path.display) "\n "

try Stdout.line! "Directory contents:\n $(dir_entries_tr)\n"

Expand Down
19 changes: 0 additions & 19 deletions examples/http-get-json.roc

This file was deleted.

2 changes: 1 addition & 1 deletion examples/record-builder.roc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main! = \_args ->

Stdout.line! "Apples: $(apples)\nOranges: $(oranges)"

join_strs = \fruits -> Str.joinWith fruits ", "
join_strs = \fruits -> Str.join_with fruits ", "

## This doesn't actually perform any effects, but we can imagine that it does
## for the sake of this example, maybe it fetches data from a server or reads a file.
Expand Down
4 changes: 2 additions & 2 deletions examples/sqlite.roc
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ main! = \_args ->
todo = try query_todos_by_status! db_path "todo"

try Stdout.line! "Todo Tasks:"
try List.forEachTry! todo \{ id, task } ->
try List.for_each_try! todo \{ id, task } ->
Stdout.line! "\tid: $(id), task: $(task)"

completed = try query_todos_by_status! db_path "completed"

try Stdout.line! "\nCompleted Tasks:"
try List.forEachTry! completed \{ id, task } ->
try List.for_each_try! completed \{ id, task } ->
Stdout.line! "\tid: $(id), task: $(task)"

Ok {}
Expand Down
17 changes: 9 additions & 8 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
description = "Basic cli devShell flake";

inputs = {
roc.url = "github:roc-lang/roc";

# TODO restore when https://github.com/roc-lang/roc/pull/7463 lands in main
roc.url = "github:smores56/roc?ref=auto-snake-case";

nixpkgs.follows = "roc/nixpkgs";

Expand Down
2 changes: 1 addition & 1 deletion platform/Env.roc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ decode! = \name ->
dict! : {} => Dict Str Str
dict! = \{} ->
Host.env_dict! {}
|> Dict.fromList
|> Dict.from_list

# ## Walks over the process's environment variables as key-value arguments to the walking function.
# ##
Expand Down
30 changes: 15 additions & 15 deletions platform/EnvDecoding.roc
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ decode_bytes_to_num = \bytes, transformer ->

Err _ -> { result: Err TooShort, rest: bytes }

env_u8 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toU8
env_u16 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toU16
env_u32 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toU32
env_u64 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toU64
env_u128 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toU128
env_i8 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toI8
env_i16 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toI16
env_i32 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toI32
env_i64 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toI64
env_i128 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toI128
env_f32 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toF32
env_f64 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toF64
env_dec = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.toDec
env_u8 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_u8
env_u16 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_u16
env_u32 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_u32
env_u64 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_u64
env_u128 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_u128
env_i8 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_i8
env_i16 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_i16
env_i32 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_i32
env_i64 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_i64
env_i128 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_i128
env_f32 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_f32
env_f64 = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_f64
env_dec = Decode.custom \bytes, @EnvFormat {} -> decode_bytes_to_num bytes Str.to_dec

env_bool = Decode.custom \bytes, @EnvFormat {} ->
when Str.from_utf8 bytes is
Expand All @@ -71,14 +71,14 @@ env_list = \decode_elem -> Decode.custom \bytes, @EnvFormat {} ->
# a whole list of bytes anyway.
decode_elems = \all_bytes, accum ->
{ to_parse, remainder } =
when List.splitFirst all_bytes (Num.to_u8 ',') is
when List.split_first all_bytes (Num.to_u8 ',') is
Ok { before, after } ->
{ to_parse: before, remainder: Some after }

Err NotFound ->
{ to_parse: all_bytes, remainder: None }

when Decode.decodeWith to_parse decode_elem (@EnvFormat {}) is
when Decode.decode_with to_parse decode_elem (@EnvFormat {}) is
{ result, rest } ->
when result is
Ok val ->
Expand Down

0 comments on commit 89dc0fe

Please sign in to comment.