ciren / cilib

Typesafe, purely functional Computational Intelligence
https://cilib.net
Apache License 2.0
124 stars 101 forks source link

Correct `choices` function #299

Closed gpampara closed 6 years ago

gpampara commented 6 years ago

The function was returning invalid results due to referencing the wrong data structure. Some additional logic is now also included to make sure that the operation behaves a little more efficiently.

MetricSpace did not use the memoization scheme correctly, resulting in no benefit actually being present. This is now correct, referencing the memoization map structure.

gpampara commented 6 years ago

What would the correct behaviour be? Request n values and then you get back m instead is wrong.

KyleErwin commented 6 years ago

Was just wondering if n is greater than the list size should duplicates then be allowed. But that behavior is better off with something like

RVar.choose(NonEmptyList(...)).replicateM(n)
gpampara commented 6 years ago

Yeah, I would be very hesitant to overload the behaviour like that. It seems very out of the functions scope.