nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
3c88f81
)
lib: rewrite Collection::rand without explicit closure
author
Jean Privat
<jean@pryen.org>
Thu, 6 Dec 2012 06:06:28 +0000
(
01:06
-0500)
committer
Jean Privat
<jean@pryen.org>
Thu, 6 Dec 2012 22:13:45 +0000
(17:13 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>
lib/standard/math.nit
patch
|
blob
|
history
diff --git
a/lib/standard/math.nit
b/lib/standard/math.nit
index
1a0f813
..
aa74174
100644
(file)
--- a/
lib/standard/math.nit
+++ b/
lib/standard/math.nit
@@
-45,21
+45,13
@@
redef class Collection[ E ]
fun rand : nullable E
do
if is_empty then return null
-
var rand_index = length.rand
- var picked : nullable E = null
- iterate !each( e ) do
- if rand_index == 0
- then
- picked = e
- break
- else
- rand_index -= 1
- end
+ for e in self do
+ if rand_index == 0 then return e
+ rand_index -= 1
end
-
- return picked
+ abort
end
end