karelpeeters
08/28/2018, 5:55 AMfold for things like that.Shawn
08/28/2018, 5:58 AMreduce since the transform is just acc + next until the end?karelpeeters
08/28/2018, 6:08 AMShawn
08/28/2018, 6:12 AMreduce on a potentially empty list?Shawn
08/28/2018, 6:14 AMif (list.isEmpty()) ... else reduce ...?edwardwongtl
08/28/2018, 6:15 AMlist.run {
if (it.isEmpty) return 0
else return it.reduce(...)
}Shawn
08/28/2018, 6:16 AMrun blockShawn
08/28/2018, 6:17 AMreturn if (list.isEmpty()) BigDecimal(0) else list.reduce { ... }Shawn
08/28/2018, 6:17 AMreduce is kinda unsafe in that regardShawn
08/28/2018, 6:18 AMfoldkarelpeeters
08/28/2018, 6:40 AMreduce is safe, it just returns null if empty.karelpeeters
08/28/2018, 6:41 AMlist.reduce(...) ?: BigDecimal.Zero is the same as the fold way.marstran
08/28/2018, 8:27 AMkarelpeeters
08/28/2018, 10:11 AM