Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Model string value from external system

$
0
0

Off topic because I don’t think non-empty string was what you were after literally, but with v11 and unboxed variants, you can easily model a non empty string in the type system:

@unboxed type str = | @as("") EmptyString | String(string)

let print = s =>
  switch s {
  | EmptyString => "empty!"
  | String(str) => str
  }

Console.log(("" :> str)->print)
Console.log(("Hello" :> str)->print)

This doesn’t make much sense of course because you could just as easily match on an empty string directly, but still a fun little effect from untagged variants.


Viewing all articles
Browse latest Browse all 2592

Trending Articles