Skip to content

Error handling variants for iteratees  #82

@Southclaws

Description

@Southclaws

Quite frequently, I want to do something like lo.Map(slice, Transformer) but Transformer returns (R, error).

I can write a function literal and handle the error, but it's still not ergonomic as there's no proper way to return the error.

So, I propose (and I can submit a PR for this) a variant of Map (and maybe others that make sense) that looks like this:

func Map[T any, R any](collection []T, iteratee func(T, int) (R, error)) ([]R, error)

Where, if the iteratee returns an error, the entire iteration stops, returns an empty list and an error (or maybe returns what it has so far)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions