← Back to context

Comment by TheDong

1 hour ago

> A for loop is more readable than the lambda soup.

Let's assume you have as slice of strings you want to uppercase. Which of the following is more readable?

    uppercased := slices.Map(inputSlice, strings.ToUpper)
    // or
    uppercased := make([]string, 0, len(inputSlice))
    for _, s := range inputSlice {
      uppercased = append(uppercased, strings.ToUpper(s))
    }

Let's say you want to parse a bunch of user-given inputs into durations, surely the following is more readable?

    parsed, err := slices.MapErr(inputstrings, time.ParseDuration)

I think map functions lead to cleaner code when used like the above, and a lot of for loops end up falling into those patterns.