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

Hard to read code when using Thoth.Json #685

Closed
lydell opened this issue Feb 16, 2020 · 4 comments
Closed

Hard to read code when using Thoth.Json #685

lydell opened this issue Feb 16, 2020 · 4 comments

Comments

@lydell
Copy link

lydell commented Feb 16, 2020

https://thoth-org.github.io/Thoth.Json/

I think this is very hard to read when the arguments to map3 after the fun are bunched up to the right. At first glance it looks like they are part of the | None -> branch.

Decode.map3 (fun aggregateId event commitPayload ->
    match commitPayload with
    | Some payload ->
        Some
            { AggregateId = AggregateId aggregateId
              Event = event
              Payload = payload }
    | None -> None) (Decode.field "aggregate_id" Decode.string) (Decode.field "event" Decode.string) decodePayload

Something like this would be better:

Decode.map3
    (fun aggregateId event commitPayload ->
        match commitPayload with
        | Some payload ->
            Some
                { AggregateId = AggregateId aggregateId
                  Event = event
                  Payload = payload }
        | None -> None
    )
    (Decode.field "aggregate_id" Decode.string)
    (Decode.field "event" Decode.string)
    decodePayload

Thanks!

@nojaf
Copy link
Contributor

nojaf commented Feb 17, 2020

Fantomas has as general rule if it fits on one line it should.
You can change the PageWidth to something smaller:
See:
https://jindraivanek.gitlab.io/fantomas-ui/#?fantomas=preview&code=CIUwxg9gJiB0C2BDADgZgAQAoBmBXAduogObEBOIxiALiAJJTogBuI+16k88AltQAqIAngBsIiRgFoAfAFgAUOiXok1MAAtOEbn0GjxjAO591C5egA+6AMraQ6ZMLET0Ms+eW34Idx48BvdABBUgoqWgZ0AF5g0MoaekYScniIqF8-DwBRVnZoplzqDMzlPWdGGMd9FwBfDKsAOQh8exl0JpaASixQSBhYbB4QEUYAImSwhIB9HihR9F7oOABnajIefGJuzEX+weGxljZqed2VtY2t9Bg+kDKDIA&config=N4IgCghg5gpg6gSwCYBcAWIBcBGADLgXyA
The result is somewhat smaller but not what you propose.

Another workaround could to add // at the end where you wish to force a line break.
However, I discovered #687 while trying that.

@nojaf
Copy link
Contributor

nojaf commented Aug 16, 2020

@nojaf
Copy link
Contributor

nojaf commented Oct 26, 2020

Fixed as part of #1202.
See example.

@nojaf nojaf closed this as completed Oct 26, 2020
@lydell
Copy link
Author

lydell commented Oct 26, 2020

Awesome! Thank you so much! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants