Let I have such code on C#. How to rewrite in function style this brunchin logic with F#? What should i use pattern matching? active pattern matching?discriminated unions?
public class DataBase
{
public List<string> GetEmployees(string id, string email)
{
if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(email))
{
return GetByIdAndEmail(id, email);
}
else if (!string.IsNullOrEmpty(email))
{
return GetByEmail(email);
}
else if (!string.IsNullOrEmpty(id))
{
return GetById(id);
}
else
{
return new List<string>();
}
}
private List<string> GetByIdAndEmail(string id, string email)
{
// request something in db
return new List<string>() { "First" };
}
private List<string> GetByEmail(string email)
{
//request something in db
return new List<string>() { "Second" };
}
private List<string> GetById(string id)
{
// request something in db
return new List<string>() { "Third" };
}
}
class Program
{
static void Main(string[] args)
{
DataBase DB = new DataBase();
string id = null;
string email = null;
DB.GetEmployees(id, email);
}
}
F#
let GetEmployees (id:string)(email:string) =
match (id,email) with
...