From 4475225984547770ef1eafc1b2c4e6f751a2d3ba Mon Sep 17 00:00:00 2001 From: Jesse Slicer Date: Tue, 19 Feb 2019 15:13:46 -0600 Subject: [PATCH] Update Projected.cs Cached the value of `result.Support()` in method `Distribution` and changed call to `.First()` to a call to `.Single()` since we know there's only one element in `support` and it better declares intent. --- Probability/Projected.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Probability/Projected.cs b/Probability/Projected.cs index 29aae74..559665d 100644 --- a/Probability/Projected.cs +++ b/Probability/Projected.cs @@ -14,8 +14,10 @@ public static IDiscreteDistribution Distribution( Func projection) { var result = new Projected(underlying, projection); - if (result.Support().Count() == 1) - return Singleton.Distribution(result.Support().First()); + var support = result.Support().ToList(); + + if (support.Count() == 1) + return Singleton.Distribution(support.Single()); return result; } private Projected(