Skip to content

Example code without infix operators #7

@alavkx

Description

@alavkx

I'm struggling to understand the decoding example in the tests

    let decode: Js.Json.t => Belt.Result.t(t, string) =
      json => {
        make
        <$> JD.intFor("userId", json)
        <*> JD.intFor("id", json)
        <*> JD.stringFor("title", json)
        <*> JD.boolFor("completed", json)
        |> Relude.Result.fromValidation
        |> Relude.Result.mapError(_ => "Decode failed");
      };

Would this be equal to the following?

let decode: Js.Json.t => Belt.Result.t(t, string) =
      json => {
        make
        |> map(JD.intFor("userId", json))
        |> ap(JD.intFor("id", json))
        |> ap(JD.stringFor("title", json))
        |> ap(JD.boolFor("completed", json))
        |> Relude.Result.fromValidation
        |> Relude.Result.mapError(_ => "Decode failed");
      };

With some direction, I'd be glad to open a PR adding examples sans infix operators. It would be nice to able to see the two versions side by side for mere mortals like I.

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