aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Saxton <peterhsaxton@gmail.com>2020-06-07 18:31:52 +0100
committerLouis Pilfold <louis@lpil.uk>2020-06-07 20:36:07 +0100
commitee63ca3e085204468f00791695c6bd5a3195512b (patch)
treec3fab9176a76809d96518dc5a2603f291a35ed13
parentfcd466289dbe248023d748dab6ac4b52da36ad6a (diff)
downloadgleam_stdlib-ee63ca3e085204468f00791695c6bd5a3195512b.tar.gz
gleam_stdlib-ee63ca3e085204468f00791695c6bd5a3195512b.zip
use map in place of list
-rw-r--r--src/gleam/os.gleam4
-rw-r--r--test/gleam/os_test.gleam6
2 files changed, 6 insertions, 4 deletions
diff --git a/src/gleam/os.gleam b/src/gleam/os.gleam
index 027ef6e..8ae522d 100644
--- a/src/gleam/os.gleam
+++ b/src/gleam/os.gleam
@@ -1,6 +1,7 @@
//// Function to interact with the host operating system.
import gleam/list
+import gleam/map.{Map}
import gleam/string
// Internal type for erlang interop.
@@ -22,7 +23,7 @@ external fn string_to_char_list(String) -> CharList =
"erlang" "binary_to_list"
/// Return all environment variables set on the system.
-pub fn get_env() -> List(tuple(String, String)) {
+pub fn get_env() -> Map(String, String) {
list.map(
os_getenv(),
fn(char_list) {
@@ -30,6 +31,7 @@ pub fn get_env() -> List(tuple(String, String)) {
value
},
)
+ |> map.from_list()
}
/// Set an environment variable.
diff --git a/test/gleam/os_test.gleam b/test/gleam/os_test.gleam
index b632331..f248d2b 100644
--- a/test/gleam/os_test.gleam
+++ b/test/gleam/os_test.gleam
@@ -1,15 +1,15 @@
-import gleam/list
+import gleam/map
import gleam/os
import gleam/should
pub fn env_test() {
os.insert_env("GLEAM_TEST", "hello")
os.get_env()
- |> list.key_find("GLEAM_TEST")
+ |> map.get("GLEAM_TEST")
|> should.equal(Ok("hello"))
os.delete_env("GLEAM_TEST")
os.get_env()
- |> list.key_find("GLEAM_TEST")
+ |> map.get("GLEAM_TEST")
|> should.equal(Error(Nil))
}