many languages will allow you to succinctly express the concept of "the type of this element is a or b"
e.g. typescript:
https://www.typescriptlang.org/docs/handbook/2/everyday-type...
Rust:
https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html
F# :
https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...
IDK, allowing that kind of type to be declared seems like a good thing to me? Those links have good examples of where it's useful. You'd need a good reason to use actually "function or regexp" in actual code though.