0

I have a query where I am calculating flag and based on the flag value, I am filtering users. Is there a way to store flag value inside query so that I dont need to call flag function twice?

 [Name("AutoRepoRule")]
    public class AutoRepossessionRule : BaseRule
    {
        public override void Define()
        {
            CReport cReport = default;

            IEnumerable<Report> reports = default;
            IEnumerable<Report> failedUser = default;

            When()
                .Match(() => cReport,
                    c => c.Product == "ABC" &&
                         c.reports.Any(x => GetAutoRepoFlag(x.Liabilities)))
                .Let(() => failedUser, () => cReport.reports
                    .Where(x => GetAutoRepoFlag(x.Liabilities)));

            Then()
                .Do(ctx => DeclineApplication(failedUser, ref cReport,
                    "Rejected"))
                .Do(ctx => ctx.Insert("AutoRepoRule"));
        }
    }

where as

 protected bool GetAutoRepoFlag(List<Liability> liabilities)
{
  .
  .
  .
}

Is there a way to store flag inside Any so that I dont need to call GetAutoRepoFlag() function twice

user14463446
  • 99
  • 10
  • Can you please check your rule? You are saying you calling the function the second time to filter users, yet you are calling it on the reports again. – Sergiy Nikolayev Jan 27 '23 at 03:24

0 Answers0