lib: changes the behavior of Coll::rand to behave like first
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 13 Jan 2014 23:24:07 +0000 (18:24 -0500)
committerAlexis 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

index 04816e9..269f3bc 100644 (file)
@@ -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