nitlanguage
/
nit.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(from parent 1:
0dbe109
)
lib: changes the behavior of Coll::rand to behave like first
author
Alexis Laferrière
<alexis.laf@xymus.net>
Mon, 13 Jan 2014 23:24:07 +0000
(18:24 -0500)
committer
Alexis Laferrière
<alexis.laf@xymus.net>
Wed, 29 Jan 2014 14:32:34 +0000
(09:32 -0500)
It will now return a non-nullable and `abort` when empty.
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>
lib/standard/math.nit
patch
|
blob
|
history
diff --git
a/lib/standard/math.nit
b/lib/standard/math.nit
index
04816e9
..
269f3bc
100644
(file)
--- a/
lib/standard/math.nit
+++ b/
lib/standard/math.nit
@@
-48,10
+48,11
@@
redef class Float
end
redef class Collection[ E ]
- # Return a random element in the collection
- fun rand : nullable E
+ # Return a random element form the collection
+ # There must be at least one element in the collection
+ fun rand: E
do
- if is_empty then return null
+ if is_empty then abort
var rand_index = length.rand
for e in self do