Я думаю, что этого достаточно:
let getByIdAndEmail id email = ["First"]
let getByEmail email = ["Second"]
let getById id = ["Third"]
let getEmployees id email =
match String.IsNullOrEmpty id, String.IsNullOrEmpty email with
| false, false -> getByIdAndEmail id email
| true, false -> getByEmail email
| false, true -> getById id
| _ -> []
Если вы хотите использовать мощь системы типов F # и ее краткий синтаксис, я предлагаю пойти дальше, написав новый строковый тип, в котором его содержимоегарантированно не будет нулевым или пустым.Так что каждый будет чувствовать себя в безопасности при использовании значений этого типа.
type ReallyString = private ReallyString of string with
static member Create s = match String.IsNullOrEmpty s with
| true -> None
| false -> Some (ReallyString s)
member this.Value = let (ReallyString s) = this in s
let getByIdAndEmail (id : ReallyString) (email : ReallyString) =
// Yay, I feel safe because the id and email really have content
// I can use id.Value and email.Value without any worry
["First"]
let getByEmail (email : ReallyString) =
// Yay, I feel safe because the email really has content
// I can use email.Value without any worry
["Second"]
let getById (id : ReallyString) =
// Yay, I feel safe because the id really has content
// I can use id.Value without any worry
["Third"]
let getEmployees id email =
// I feel unsafe here, so I have to check
// Actually I'm being forced to check because if I don't check
// I won't have valid values to pass to the getByXXX functions above
match ReallyString.Create id, ReallyString.Create email with
| Some reallyId, Some reallyEmail -> getByIdAndEmail reallyId reallyEmail
| Some reallyId, None -> getById reallyId
| None, Some reallyEmail -> getByEmail reallyEmail
| _ -> []