From 433ca621d3265e36be30d82587c2ef3e98470db9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 13 Jan 2014 18:24:07 -0500 Subject: [PATCH 1/1] lib: changes the behavior of Coll::rand to behave like first MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It will now return a non-nullable and `abort` when empty. Signed-off-by: Alexis Laferrière --- lib/standard/math.nit | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/standard/math.nit b/lib/standard/math.nit index 04816e9..269f3bc 100644 --- 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 -- 1.7.9.5