Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pickRandom should not look at element types, in my opinion. #1974

Closed
fweth opened this issue Sep 26, 2020 · 2 comments · Fixed by #1976
Closed

pickRandom should not look at element types, in my opinion. #1974

fweth opened this issue Sep 26, 2020 · 2 comments · Fixed by #1976

Comments

@fweth
Copy link

fweth commented Sep 26, 2020

pickRandom wants a one-dimensional array. I understand the design decision, but it still feels not so intuitive, I expect pickRandom to only look at the length of my array and then return the element at a random index. So e.g. math.pickRandom([[0, 1], [2, 3]]) should randomly return either [0, 1] or [2, 3]. After all, pickRandom([0, [1, 2], [3, 4]]) works as expected. Even if we pretend that JS is a strictly typed language with no mixed arrays, I'd expect pickRandom to be of type forall a. [a] -> M a where M is a suitable monad.

@josdejong
Copy link
Owner

Thanks @fweth , that is a good point. I think there is no reason to only allow a 1d array, we could simply iterate over all elements.

Anyone interested in helping improve pickRandom in this regard?

@josdejong
Copy link
Owner

josdejong commented Oct 7, 2020

Improvement is now available in v7.4.0 v7.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants