Skip to content

Self documenting code is unnecessarily cryptic #1882

Description

@gdennie

The following does not easily suggest the types in its Result.

fn map_res<G, O2, E2>(self, g: G) -> MapRes<Self, G>
where
    G: FnMut(Self::Output) -> Result<O2, E2>,
    Self::Error: FromExternalError<Input, E2>,
    Self: Sized,

Applies a function returning a Result over the result of a parser.

...perhaps something as follows:

fn map_res<G, Output, Error>(self, g: G) -> MapRes<Self, G>
where
    G: FnMut(Self::Output) -> Result<Output, Error>,
    Self::Error: FromExternalError<Input, Error>,
    Self: Sized,

Applies a function returning a Result over the result of a parser.

or even clearer...

fn map_res<G, NewOutput, NewError>(self, g: G) -> MapRes<Self, G>
where
    G: FnMut(Self::Output) -> Result<NewOutput, NewError>,
    Self::Error: FromExternalError<Input, NewError>,
    Self: Sized,

Applies a function returning a Result over the result of a parser.

What is clear can become hard to see after long familiarity. I only belatedly appreciated the intended numbering sequence: O1, O2, etc. However, it is a mental tax I'd prefer to spend elsewhere, especially when such brevity is not necessary. Ease of use is also technological sophistication.

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