samber / mo

🦄 Monads and popular FP abstractions, powered by Go 1.18+ Generics (Option, Result, Either...)
https://pkg.go.dev/github.com/samber/mo
MIT License
2.61k stars 85 forks source link

Fix the Map for Option type #41

Open tomohavvk opened 4 months ago

tomohavvk commented 4 months ago

After the first touch of Option type I was confused how the Map is implemented.

In my understanding of functional programming the Map should be applied only for a value and return the value, and never return the no-value.

For case when need to apply function for a value and return Some or None the FlatMap should be used.

Before:

Some(1).
  Map(func(value int) (int, bool) {
    return value + 21, true
  })

After:

Some(1).
  Map(func(value int) int {
    return value + 21
  })
samber commented 3 months ago

Since this introduces a breaking change, we must wait for v2.