From 5392ea33d25b1545c793560bd694a9f6e75edca3 Mon Sep 17 00:00:00 2001 From: Brendan Hansknecht Date: Thu, 30 Nov 2023 23:28:41 -0800 Subject: [PATCH] Add default Inspect to opaque types Also, ran `roc format src/` --- src/Cmd.roc | 12 +++++------- src/EnvDecoding.roc | 42 +++++++++++++++++++++--------------------- src/FileMetadata.roc | 1 + src/InternalPath.roc | 2 +- src/Stdin.roc | 10 +++++----- src/Url.roc | 16 ++++++++-------- src/Utc.roc | 2 +- 7 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/Cmd.roc b/src/Cmd.roc index e9ae5b77..c2a17696 100644 --- a/src/Cmd.roc +++ b/src/Cmd.roc @@ -20,7 +20,7 @@ interface Cmd ] ## Represents a command to be executed in a child process. -Cmd := InternalCommand.Command +Cmd := InternalCommand.Command implements [Inspect] ## Errors from executing a command. Error : InternalCommand.CommandErr @@ -125,16 +125,14 @@ output : Cmd -> Task Output (Output, Error) output = \@Cmd cmd -> Effect.commandOutput (Box.box cmd) |> Effect.map \internalOutput -> - out = - { - stdout: internalOutput.stdout, - stderr: internalOutput.stderr, - } + out = { + stdout: internalOutput.stdout, + stderr: internalOutput.stderr, + } when internalOutput.status is Ok {} -> Ok (out) Err err -> Err (out, err) - |> InternalTask.fromEffect ## Execute command and inheriting stdin, stdout and stderr from parent diff --git a/src/EnvDecoding.roc b/src/EnvDecoding.roc index 463c4ca5..b8171439 100644 --- a/src/EnvDecoding.roc +++ b/src/EnvDecoding.roc @@ -1,27 +1,27 @@ interface EnvDecoding exposes [EnvFormat, format] imports [] EnvFormat := {} implements [ - DecoderFormatting { - u8: envU8, - u16: envU16, - u32: envU32, - u64: envU64, - u128: envU128, - i8: envI8, - i16: envI16, - i32: envI32, - i64: envI64, - i128: envI128, - f32: envF32, - f64: envF64, - dec: envDec, - bool: envBool, - string: envString, - list: envList, - record: envRecord, - tuple: envTuple, - }, - ] + DecoderFormatting { + u8: envU8, + u16: envU16, + u32: envU32, + u64: envU64, + u128: envU128, + i8: envI8, + i16: envI16, + i32: envI32, + i64: envI64, + i128: envI128, + f32: envF32, + f64: envF64, + dec: envDec, + bool: envBool, + string: envString, + list: envList, + record: envRecord, + tuple: envTuple, + }, + ] format : {} -> EnvFormat format = \{} -> @EnvFormat {} diff --git a/src/FileMetadata.roc b/src/FileMetadata.roc index 84855eb6..aeb12318 100644 --- a/src/FileMetadata.roc +++ b/src/FileMetadata.roc @@ -12,6 +12,7 @@ FileMetadata := { isReadonly : Bool, mode : [Unix U32, NonUnix], } + implements [Inspect] ## Returns the number of bytes in the associated file. bytes : FileMetadata -> U64 diff --git a/src/InternalPath.roc b/src/InternalPath.roc index 10ebe7f0..c2d3de45 100644 --- a/src/InternalPath.roc +++ b/src/InternalPath.roc @@ -10,7 +10,7 @@ interface InternalPath ] imports [] -InternalPath := UnwrappedPath +InternalPath := UnwrappedPath implements [Inspect] UnwrappedPath : [ # We store these separately for two reasons: diff --git a/src/Stdin.roc b/src/Stdin.roc index ff4d0885..989b3877 100644 --- a/src/Stdin.roc +++ b/src/Stdin.roc @@ -1,7 +1,7 @@ interface Stdin exposes [ - line, - bytes, + line, + bytes, ] imports [Effect, Task.{ Task }, InternalTask] @@ -14,7 +14,7 @@ interface Stdin line : Task [Input Str, End] * line = Effect.stdinLine - |> Effect.map \r -> + |> Effect.map \r -> when r is Ok str -> Ok (Input str) Err _ -> Ok End @@ -22,11 +22,11 @@ line = ## Read bytes from [standard input](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)). ## -## > This is typically used in combintation with [Tty.enableRawMode], +## > This is typically used in combintation with [Tty.enableRawMode], ## which disables defaults terminal bevahiour and allows reading input ## without buffering until Enter key is pressed. bytes : Task (List U8) * bytes = Effect.stdinBytes |> Effect.map Ok - |> InternalTask.fromEffect \ No newline at end of file + |> InternalTask.fromEffect diff --git a/src/Url.roc b/src/Url.roc index 069c2a99..3288a393 100644 --- a/src/Url.roc +++ b/src/Url.roc @@ -19,7 +19,7 @@ interface Url ## ## It could be an absolute address, such as `https://roc-lang.org/authors` or ## a relative address, such as `/authors`. You can create one using [Url.fromStr]. -Url := Str +Url := Str implements [Inspect] ## Reserve the given number of bytes as extra capacity. This can avoid reallocation ## when calling multiple functions that increase the length of the URL. @@ -77,7 +77,7 @@ toStr = \@Url str -> str ## [Percent-encodes](https://en.wikipedia.org/wiki/Percent-encoding) a ## [path component](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier#Syntax) -## and appends to the end of the URL's path. +## and appends to the end of the URL's path. ## ## This will be appended before any queries and fragments. If the given path string begins with `/` and the URL already ends with `/`, one ## will be ignored. This avoids turning a single slash into a double slash. If either the given URL or the given string is empty, no `/` will be added. @@ -228,7 +228,7 @@ percentEncode = \input -> Str.concat output suffix -## Adds a [Str] query parameter to the end of the [Url]. +## Adds a [Str] query parameter to the end of the [Url]. ## ## The key and value both get [percent-encoded](https://en.wikipedia.org/wiki/Percent-encoding). ## @@ -280,10 +280,10 @@ appendParam = \@Url urlStr, key, value -> |> @Url ## Replaces the URL's [query](https://en.wikipedia.org/wiki/URL#Syntax)—the part -## after the `?`, if it has one, but before any `#` it might have. +## after the `?`, if it has one, but before any `#` it might have. ## ## Passing `""` removes the `?` (if there was one). -## +## ## ``` ## # Gives https://example.com?newQuery=thisRightHere#stuff ## Url.fromStr "https://example.com?key1=val1&key2=val2#stuff" @@ -327,7 +327,7 @@ withQuery = \@Url urlStr, queryStr -> |> @Url ## Returns the URL's [query](https://en.wikipedia.org/wiki/URL#Syntax)—the part after -## the `?`, if it has one, but before any `#` it might have. +## the `?`, if it has one, but before any `#` it might have. ## ## Returns `""` if the URL has no query. ## @@ -372,7 +372,7 @@ hasQuery = \@Url urlStr -> |> List.contains (Num.toU8 '?') ## Returns the URL's [fragment](https://en.wikipedia.org/wiki/URL#Syntax)—the part after -## the `#`, if it has one. +## the `#`, if it has one. ## ## Returns `""` if the URL has no fragment. ## @@ -392,7 +392,7 @@ fragment = \@Url urlStr -> Ok { after } -> after Err NotFound -> "" -## Replaces the URL's [fragment](https://en.wikipedia.org/wiki/URL#Syntax). +## Replaces the URL's [fragment](https://en.wikipedia.org/wiki/URL#Syntax). ## ## If the URL didn't have a fragment, adds one. Passing `""` removes the fragment. ## diff --git a/src/Utc.roc b/src/Utc.roc index 6379560c..756fd2b7 100644 --- a/src/Utc.roc +++ b/src/Utc.roc @@ -12,7 +12,7 @@ interface Utc imports [Effect, InternalTask, Task.{ Task }] ## Stores a timestamp as nanoseconds since UNIX EPOCH -Utc := U128 +Utc := U128 implements [Inspect] ## Duration since UNIX EPOCH now : Task Utc *