samhh / fp-ts-std

The missing pseudo-standard library for fp-ts.
https://samhh.github.io/fp-ts-std/
MIT License
207 stars 27 forks source link

`NES.unsafeFromString` should throw #165

Closed samhh closed 1 year ago

samhh commented 1 year ago

If the smart constructor's predicate fails, ideally the unsafe constructor throws instead of lifting an invalid value to the newtype. This acts as a small convenience over the consumer having to unsafely unwrap the Option themselves, and we can provide a consistent error message.

A bit of Haskell prior art: https://wiki.haskell.org/Smart_constructors#Smart.28er.29_constructors

samhh commented 1 year ago

https://github.com/samhh/fp-ts-std/commit/d515ab23c24ff84baa57f403e22b9edcb794cff8