From 8afce582af1fedd5d65582f2fec79a003c4f2a5c Mon Sep 17 00:00:00 2001 From: nsensfel Date: Tue, 23 Apr 2019 17:21:52 +0200 Subject: Adds an ordset update function. --- src/ataxic_sugar.erl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src') diff --git a/src/ataxic_sugar.erl b/src/ataxic_sugar.erl index 556e08a..eb0ef57 100644 --- a/src/ataxic_sugar.erl +++ b/src/ataxic_sugar.erl @@ -12,6 +12,7 @@ [ update_array_cell/2, update_orddict_element/2, + update_ordset/2, nop/0 ] ). @@ -84,3 +85,32 @@ update_orddict_element (IX, OP) -> -spec nop () -> ataxic:basic(). nop () -> ataxic:sequence([]). + +-spec update_ordset (ordsets:ordset(), ordsets:ordeset()) -> ataxic:basic(). +update_ordset (Old, New) -> + Remove = ordsets:substract(Old, New), + Add = ordsets:substract(New, Old), + + ataxic:sequence + ( + [ + ataxic:apply_function + ( + ordsets, + substract, + [ + ataxic:current_value(), + ataxic:constant(Remove) + ] + ), + ataxic:apply_function + ( + ordsets, + union, + [ + ataxic:current_value(), + ataxic:constant(Add) + ] + ) + ] + ). -- cgit v1.2.3-70-g09d2