Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decode.recursive documentation #789

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/gleam/dynamic/decode.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,6 @@ pub fn failure(zero: a, expected: String) -> Decoder(a) {
/// build-in `string` decoder) you would define it like so:
///
/// ```gleam
/// import gleam/dynamic
/// import decode/decode
///
/// pub fn string_decoder() -> decode.Decoder(String) {
/// let default = ""
/// decode.new_primitive_decoder("String", fn(data) {
Expand All @@ -995,26 +992,23 @@ pub fn new_primitive_decoder(
})
}

/// Create a decoder that can refer to itself, useful for decoding for deeply
/// Create a decoder that can refer to itself, useful for decoding deeply
/// nested data.
///
/// Attempting to create a recursive decoder without this function could result
/// in an infinite loop. If you are using `field` or other `use`able function
/// in an infinite loop. If you are using `field` or other `use`able functions
/// then you may not need to use this function.
///
/// ```gleam
/// import gleam/dynamic
/// import decode/zero.{type Decoder}
///
/// type Nested {
/// Nested(List(Nested))
/// Value(String)
/// }
///
/// fn nested_decoder() -> Decoder(Nested) {
/// use <- zero.recursive
/// zero.one_of(zero.string |> zero.map(Value), [
/// zero.list(nested_decoder()) |> zero.map(Nested),
/// fn nested_decoder() -> decode.Decoder(Nested) {
/// use <- decode.recursive
/// decode.one_of(decode.string |> decode.map(Value), [
/// decode.list(nested_decoder()) |> decode.map(Nested),
/// ])
/// }
/// ```
Expand Down