Skip to content

Suggestion: Add decode.number #801

Open
@sbergen

Description

@sbergen

Context

Given that

  1. the decode API is used with formats like JSON, where there is no distinction between floats and ints, and
  2. the target (Erlang vs ES) is a somewhat leaky abstraction when it comes to handling numbers,

it can be confusing that on the Erlang target decode.float will not accept e.g. 1, but requires 1.0 to work properly.

Suggestion

Add decode.number: Decoder(Float), which would work equivalently to

decode.one_of(decode.float, or: [decode.int |> decode.map(int.to_float)])

This would both make it more convenient to decode formats where there's no distinction between ints and floats, and act as documentation about the context outlined above.

If this sounds like a good idea, I'd be happy to create a PR for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions