Skip to content

Proposal: add func like Map but with iteratee which may return an error #342

@genvmoroz

Description

@genvmoroz

Hi!

I found this package very useful, I wish I find it early.

But I have one small proposal: it may be useful also having one func near lo.Map which may return an error if conversion fails.
For example we have slice of string and want to map it to slice of int.
Right now we must to add extra sugar to catch any errors in current lo.Map if we don't need it panic.
Just as an example, new function it may look like:

ss := []string{"1", "2", "invalid"}
res, err := lo.MapAmbiguous(ss, strconv.Atoi)
// handle an error

Let me know what you think of it.

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