]> gitweb.factorcode.org Git - factor.git/commitdiff
assocs.extras: Add ?set-once-at returning the value it set or looked up
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 28 Feb 2023 06:17:50 +0000 (00:17 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 28 Feb 2023 06:17:50 +0000 (00:17 -0600)
extra/assocs/extras/extras.factor

index 8ac28df46eebe6dfbbd04a8339952d500caad8f6..e4e35522ca08b38b4ada500c6534ff2acb084d2d 100644 (file)
@@ -148,6 +148,9 @@ ERROR: key-exists value key assoc ;
         drop set-at
     ] if ;
 
+: ?set-once-at ( value key assoc -- value' first-time? )
+    [ ?at not ] keep '[ [  _ set-at ] keepd t ] [ nip f ] if ;
+
 : kv-with ( obj assoc quot -- assoc curried )
     swapd [ -rotd call ] 2curry ; inline