From d4ea952032b099a4674c27e964ab6ec421c690f4 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Fri, 26 Apr 2019 23:21:22 +0200 Subject: Dubious way to have lazy orddict updates. I want to keep the benefits of orddict:fetch vs orddict:find, but still be able to re-use the existing code when adding a new element. --- src/ataxic_sugar.erl | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src/ataxic_sugar.erl') diff --git a/src/ataxic_sugar.erl b/src/ataxic_sugar.erl index 3098196..7f6e441 100644 --- a/src/ataxic_sugar.erl +++ b/src/ataxic_sugar.erl @@ -64,20 +64,26 @@ update_orddict_element (IX, OP) -> store, [ ataxic:constant(IX), - ataxic:sequence ( - [ - ataxic:apply_function - ( - orddict, - fetch, - [ - ataxic:constant(IX), - ataxic:current_value() - ] - ), - OP - ] + case ataxic:is_constant(OP) of + true -> OP; + false -> + ataxic:sequence + ( + [ + ataxic:apply_function + ( + orddict, + fetch, + [ + ataxic:constant(IX), + ataxic:current_value() + ] + ), + OP + ] + ) + end ), ataxic:current_value() ] -- cgit v1.2.3-70-g09d2