From 89dc0fedb62e115ca0ff1bb2f7bf68b282c0f40b Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Wed, 8 Jan 2025 09:25:38 +1100 Subject: [PATCH] remove examples/http-get-json.roc, update flake, fix builtins --- ci/expect_scripts/http-get-json.exp | 27 -------------------------- examples/dir.roc | 2 +- examples/env-var.roc | 4 ++-- examples/file-mixed.roc | 2 +- examples/http-get-json.roc | 19 ------------------ examples/record-builder.roc | 2 +- examples/sqlite.roc | 4 ++-- flake.lock | 17 ++++++++-------- flake.nix | 4 +++- platform/Env.roc | 2 +- platform/EnvDecoding.roc | 30 ++++++++++++++--------------- 11 files changed, 35 insertions(+), 78 deletions(-) delete mode 100644 ci/expect_scripts/http-get-json.exp delete mode 100644 examples/http-get-json.roc diff --git a/ci/expect_scripts/http-get-json.exp b/ci/expect_scripts/http-get-json.exp deleted file mode 100644 index d2af026a..00000000 --- a/ci/expect_scripts/http-get-json.exp +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/expect - -# uncomment line below for debugging -# exp_internal 1 - -set timeout 7 - -source ./ci/expect_scripts/shared-code.exp - -# Start server to test with in the background and capture its process ID -set server_pid [exec ./ci/rust_http_server/target/release/rust_http_server &] -sleep 3 - -spawn $env(EXAMPLES_DIR)http-get-json - -expect "The json I received was: { foo: \"Hello Json!\" }\r\n" { - exec kill $server_pid - - expect eof { - check_exit_and_segfault - } -} - -exec kill $server_pid - -puts stderr "\nError: output was different from expected value." -exit 1 diff --git a/examples/dir.roc b/examples/dir.roc index 34ddcc69..24858d45 100644 --- a/examples/dir.roc +++ b/examples/dir.roc @@ -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 diff --git a/examples/env-var.roc b/examples/env-var.roc index 0c083790..9cd47159 100644 --- a/examples/env-var.roc +++ b/examples/env-var.roc @@ -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)" diff --git a/examples/file-mixed.roc b/examples/file-mixed.roc index 6579cc3f..dc257639 100644 --- a/examples/file-mixed.roc +++ b/examples/file-mixed.roc @@ -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" diff --git a/examples/http-get-json.roc b/examples/http-get-json.roc deleted file mode 100644 index 7b8fbcba..00000000 --- a/examples/http-get-json.roc +++ /dev/null @@ -1,19 +0,0 @@ -app [main!] { - pf: platform "../platform/main.roc", - json: "https://github.com/lukewilliamboswell/roc-json/releases/download/0.11.0/z45Wzc-J39TLNweQUoLw3IGZtkQiEN3lTBv3BXErRjQ.tar.br", -} - -# To run this example: check the README.md in this folder - -import pf.Http -import pf.Stdout -import json.Json - -# HTTP GET request with easy decoding to json -main! = \_args -> - - # Easy decoding/deserialization of { "foo": "something" } into a Roc var - { foo } = try Http.get! "http://localhost:8000" Json.utf8 - # If you want to see an example of the server side, see basic-cli/ci/rust_http_server/src/main.rs - - Stdout.line! "The json I received was: { foo: \"$(foo)\" }" diff --git a/examples/record-builder.roc b/examples/record-builder.roc index cadcac34..53b32d51 100644 --- a/examples/record-builder.roc +++ b/examples/record-builder.roc @@ -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. diff --git a/examples/sqlite.roc b/examples/sqlite.roc index ff507fae..5a60c034 100644 --- a/examples/sqlite.roc +++ b/examples/sqlite.roc @@ -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 {} diff --git a/flake.lock b/flake.lock index 077bd9fb..09b302ae 100644 --- a/flake.lock +++ b/flake.lock @@ -102,15 +102,16 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1734960752, - "narHash": "sha256-QVcT/lUgDRoBccvaZqIAefNInrN6bSuqUJNs9cfjKLY=", - "owner": "roc-lang", + "lastModified": 1736287263, + "narHash": "sha256-KkKext3lTrqSnuxgQ5J35rs1kXAMbilFPdwACsj5wrU=", + "owner": "smores56", "repo": "roc", - "rev": "a58b1013e756749da5c35431efde834a70a29717", + "rev": "3d4c3028072066b5f946d70d1fa64c5884888ea3", "type": "github" }, "original": { - "owner": "roc-lang", + "owner": "smores56", + "ref": "auto-snake-case", "repo": "roc", "type": "github" } @@ -154,11 +155,11 @@ ] }, "locked": { - "lastModified": 1734834660, - "narHash": "sha256-bm8V+Cu8rWJA+vKQnc94mXTpSDgvedyoDKxTVi/uJfw=", + "lastModified": 1736216977, + "narHash": "sha256-EMueGrzBpryM8mgOyoyJ7DdNRRk09ug1ggcLLp0WrCQ=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "b070e6030118680977bc2388868c4b3963872134", + "rev": "bbe7e4e7a70d235db4bbdcabbf8a2f6671881dd7", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index c3195b8f..17a0188a 100644 --- a/flake.nix +++ b/flake.nix @@ -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"; diff --git a/platform/Env.roc b/platform/Env.roc index 4b9c81fc..3b9a1fb9 100644 --- a/platform/Env.roc +++ b/platform/Env.roc @@ -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. # ## diff --git a/platform/EnvDecoding.roc b/platform/EnvDecoding.roc index 777e2988..761f0151 100644 --- a/platform/EnvDecoding.roc +++ b/platform/EnvDecoding.roc @@ -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 @@ -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 ->