Skip to content

Commit

Permalink
Merge pull request #139 from roc-lang/default-inspect
Browse files Browse the repository at this point in the history
Add default Inspect to opaque types
  • Loading branch information
Anton-4 committed Dec 1, 2023
2 parents fb3eade + 5392ea3 commit cd4d936
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 43 deletions.
12 changes: 5 additions & 7 deletions src/Cmd.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 21 additions & 21 deletions src/EnvDecoding.roc
Original file line number Diff line number Diff line change
@@ -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 {}
Expand Down
1 change: 1 addition & 0 deletions src/FileMetadata.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/InternalPath.roc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface InternalPath
]
imports []

InternalPath := UnwrappedPath
InternalPath := UnwrappedPath implements [Inspect]

UnwrappedPath : [
# We store these separately for two reasons:
Expand Down
10 changes: 5 additions & 5 deletions src/Stdin.roc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
interface Stdin
exposes [
line,
bytes,
line,
bytes,
]
imports [Effect, Task.{ Task }, InternalTask]

Expand All @@ -14,19 +14,19 @@ 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
|> InternalTask.fromEffect

## 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
|> InternalTask.fromEffect
16 changes: 8 additions & 8 deletions src/Url.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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).
##
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.
##
Expand Down Expand Up @@ -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.
##
Expand All @@ -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.
##
Expand Down
2 changes: 1 addition & 1 deletion src/Utc.roc
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down

0 comments on commit cd4d936

Please sign in to comment.