偶然看到同事写了这个tuple_size,以前都是用size,也没当回事,跑去查文档发现还是有区别,
tuple_size/1
Returns an integer which is the number of elements in Tuple.
> tuple_size({morni, mulle, bwange}).
3
Allowed in guard tests.
size/1
Returns an integer which is the size of the argument Item, which must be either a tuple or a binary.
> size({morni, mulle, bwange}).
3
Allowed in guard tests.
size能返回二进制和元组item大小。
tuple_size只能返回元组大小。
看描述,只有tuple的话,tuple_size效率快。回头再来做测试。