Suppose I have 2 functions
Func<Id, Option<Employee>> FindEmployee
It returns an employee if the Id is found, otherwise None
;
Func<Employee, Option<Entry>> PromptPassword
It will open a dialog asking for password, if OK button is hit, it will return the user entry; if cancel is hit, it will return None
I would like to have an elegant way to composite these 2 functions, basically I want to do:
FindEmployee.Map(emp =>
{
while (true)
{
var result = PromptPassword (emp);
if (result.IsNone)
{
return false;
}
bool matched = result.Where(a => a.EntryContent == emp.Password)
.Some(r => true)
.None(false);
if (matched)
return true;
}
});
The end result is an Option
You see, I want to keep prompting for password until the user enter it correctly. But using a while loop inside a Map
is so ugly.
It must have a better way to write this. can anyone give a hint?
Thanks