public JsonResult doit2(Rq rq) { var rq_ = Some(rq) .Where(validator.IsValid) .ForEach(doit); return(Json(new { ok = false, rq = rq, rq_ = rq_, message = "IsValid rets option , so can be chained" }, JsonRequestBehavior.AllowGet)); }
public JsonResult doit1(Rq rq) { var valid = validator.IsValid(rq); if (valid) { ///doit } return(Json(new { ok = valid, rq = rq, message = "IsValid rets bool, controller fun has an imperative if" }, JsonRequestBehavior.AllowGet)); }
public JsonResult doit3(Rq rq) { var rq_ = Some(rq) // basketise in an Option .Map(Normalise) // remove extra spaces, capitalise .Where(validator.IsValid) // is valid? .ForEach(doit); // side effect return(Json(new { ok = false, rq = rq, rq_ = rq_, message = "IsValid rets option , controller fun ..." }, JsonRequestBehavior.AllowGet)); }
public Rq Normalise(Rq rq) { if (rq != null) { rq.id = rq?.id?.Trim(); } if (rq != null) { rq.name = rq?.name?.Trim().ToUpper(); } return(rq); }
private void doit(Rq rq) { repo .Get(rq.id) .Bind(account => account.Debit(rq.transferAmount)) .ForEach(account => { // There are 2 statements here ... // They have side-effects and its both-together ... // create single Task representing both ops, // and have process that performs both // remove the task ONLY when both carried out // both ops may get performed more than once ... // => make provisions so that both tasks are idempotent repo.Save(rq.id, account); swift.Wire(rq, account); }); }