import scala.compiletime.{error, requireConst}
opaque type NonEmptyString = String
object NonEmptyString:
def apply(s: String): Option[NonEmptyString] =
if s.isEmpty then None else Some(s)
inline def from(inline s: String): NonEmptyString =
requireConst(s)
inline if s == "" then error("got an empty string") else s
given Conversion[NonEmptyString, String] with
inline def apply(nes: NonEmptyString): String = nes
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter