I already did something similar before, but in a different way. I also needed to check the result of the expression. The advantage of my trick is that you do not need to test it yourself; pattern matching does this for you. The key to the trick is to use lists: foldl. The following is an example.
check_group(Community_code,Category_code,Group_code) ->
Group = dis_scan:get_group_item(Community_code,Category_code,Group_code),
StartItems = [ start_item(Community_code,Category_code,Item_seq_no)
|| {_, _, Item_seq_no } <- Group ],
ok = lists:foldl(fun check_start_item/2, ok, StartItems),
exit(normal).
check_start_item(StartItem, ok) ->
ok.
If, on the other hand, you need to group the items by the result returned from the scan, then use the lists: section.
check_group(Community_code,Category_code,Group_code) ->
Group = dis_scan:get_group_item(Community_code,Category_code,Group_code),
StartItems = [ start_item(Community_code,Category_code,Item_seq_no)
|| {_, _, Item_seq_no } <- Group ],
{GoodItems, BadItems} = lists:partition(fun check_start_item/1, StartItems),
case BadItems of
[] -> exit(normal);
_ -> error({bad_start_items, BadItems})
end.
check_start_item(StartItem) ->
## Return true if item is ok, false otherwise.
true.