I’m not a fan of let? syntax. Mixing text and symbols just looks complicated
I propose using maybe instead.
Then the examples would look like this
/* returns: string => promise<result<decodedUser, 'errors>> */
let getUser = async (id) => {
/* if fetchUser returns Error e, the function returns Error e here. Same for all other `maybe` */
maybe Ok(user) = await fetchUser(id)
maybe Ok(decodedUser) = decodeUser(user)
Console.log(`Got user ${decodedUser.name}!`)
maybe Ok() = await ensureUserActive(decodedUser)
Ok(decodedUser)
}
I like it because maybe is already a well known convention with optionals. e.g. type maybeUser = option<user>
This might be naive, I’m not much of a language architect. Let me know what you think