pratica icon indicating copy to clipboard operation
pratica copied to clipboard

Result should require a non empty value

Open carlesba opened this issue 2 years ago • 2 comments

I think Result should require a defined value on its creation in order to guarantee a value in cata.

ie,


const format= (text: string): Result<number, string> => {
  const number = Number(text)
  return isNaN(number)? Err('bad input') : Ok(number)
}

format('2,000').cata({
  Ok: (result)=> // result is not guaranteed, can be undefined
  Err:// ...
})

format's output is a Result number, but still, we have to add a conditional guard to fix the type.

carlesba avatar Oct 11 '22 10:10 carlesba

Left a comment on your PR https://github.com/rametta/pratica/pull/30/files#r992399077, let me know what you think

rametta avatar Oct 11 '22 14:10 rametta

hey Jason, thank you for taking the time to review this. How would you use NonNullable in this case?

carlesba avatar Oct 13 '22 11:10 carlesba

I also ran into this issue. What do you think of https://github.com/rametta/pratica/pull/31?

csfalcione avatar Oct 23 '22 23:10 csfalcione

I also ran into this issue. What do you think of #31?

Looks good, just a few comments on it then we can merge

rametta avatar Oct 24 '22 13:10 rametta

This is now fixed and available in version 2.1.0 on npm.

rametta avatar Oct 25 '22 13:10 rametta