Is it intentional design that we can transform a Some to a None with a map function? For example:
function log(maybe: Maybe<unknown>) {
maybe
.map(x => console.log(`Got ${x}`))
.orElse(x => console.log(`Got nothing`))
}
Calling this function with log(some(5)) will log both "Got 5" and "Got Nothing". Since the map function doesn't return anything, it becomes a None and the orElse case runs. (This can be fixed with either .tap or .caseOf)
I can see some cases where you'd want to map from Some to None, but I think it's also unexpected in a lot of cases, like above. I don't know if this behavior is specified by any standard. I compared to fp-ts and their Optional will not map to a None in this case, it'll become Maybe<undefined>.
Is it intentional design that we can transform a
Someto aNonewith a map function? For example:Calling this function with
log(some(5))will log both "Got 5" and "Got Nothing". Since the map function doesn't return anything, it becomes aNoneand theorElsecase runs. (This can be fixed with either.tapor.caseOf)I can see some cases where you'd want to map from
SometoNone, but I think it's also unexpected in a lot of cases, like above. I don't know if this behavior is specified by any standard. I compared tofp-tsand their Optional will not map to aNonein this case, it'll becomeMaybe<undefined>.