Yonaba / Moses

Utility library for functional programming in Lua

Home Page:http://yonaba.github.io/Moses

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

_.size behavior

denisdemaisbr opened this issue · comments

Hi, this behavir is expected on: string and boolean values?

moses-size.lua
print( _VERSION );
print('no args', _.size(), 'nil', _.size(nil), 'false', _.size(false), 'true', _.size(true), 'string empty', _.size(''), '{}', _.size({}), '{{},{}}', _.size( { {}, {} }) );

lua moses-size.lua
Lua 5.1
no args 0 nil 0 false 1 true 1 string empty 1 {} 0 {{},{}} 2

This behavior is intented. Actually, when _.size receives only one argument, i.e a collection (array, table,...) it will return the count of elements inside this argument. But when it receives more than one argument, it will return the count of all the arguments received.

But actually there was some inconsistency. Thanks noticing it. _size would return 0 when the first argument given is nil, no matter what the others would be. I just fixed it.