diff --git a/modules/std/collections/map.wx b/modules/std/collections/map.wx index 706b5990..e4fb913c 100644 --- a/modules/std/collections/map.wx +++ b/modules/std/collections/map.wx @@ -843,7 +843,46 @@ Class Map If node Return node._value Return Null End + + #rem wonkeydoc Search if a contained value exists as the value of a key. + @author iDkP from GaragePixel + @since 2025-07-18 + @param key The key. + @param key The values container. Accepts [[Array]], [[Stack]] and [[List]]. + @return -1 if the key hasn't any contained values, or an index corresponding to the value's position in the container. + #end + Method Search:Int( key:K,values:Stack ) + 'Added by iDkP from GaragePixel 2025-07-18 + Return Search(key,values.Data) + End + Method Search:Int( key:K,values:V[] ) + 'Added by iDkP from GaragePixel 2025-07-18 + Local keynode:=FindNode(key) + If keynode + Local value:=FindNode(key).Value + Local valuesLength:=values.Length + For Local index:=0 Until valuesLength + If value=values[index] Return index + End + End + Return -1 + End + + Method Search:Int( key:K,values:List ) + 'Added by iDkP from GaragePixel 2025-07-18 + Local keynode:=FindNode(key) + If keynode + Local value:=keynode.Value + Local index:Int=0 + For Local item:=Eachin values + If value=item Return index + index+=1 + End + End + Return -1 + End + #rem wonkeydoc Removes a key from the map. @param key The key to remove. @return True if the key was removed, or false if the key is not in the map. diff --git a/modules/std/syntax/funcs/searchin.wx b/modules/std/syntax/funcs/searchin.wx new file mode 100644 index 00000000..9ef6d40f --- /dev/null +++ b/modules/std/syntax/funcs/searchin.wx @@ -0,0 +1,18 @@ + +Namespace std.syntax + +#rem monkeydoc @pro @sugar SearchIn collections functions. +@author iDkP from GagagePixel +@since 2025-07-18 +#end +Function SearchIn:Int( map:Map,key:K,values:Stack ) + Return map.Search( key, values.Data ) +End + +Function SearchIn:Int( map:Map,key:K,values:V[] ) + Return map.Search( key, values ) +End + +Function SearchIn:Int( map:Map,key:K,values:List ) + Return map.Search( key, values ) +End diff --git a/modules/std/syntax/functors/assignif.wx b/modules/std/syntax/functors/assignif.wx new file mode 100644 index 00000000..0968c2bd --- /dev/null +++ b/modules/std/syntax/functors/assignif.wx @@ -0,0 +1,26 @@ + +Namespace std.syntax + +#rem wonkeydoc @pro Assigns something if not null. +@author iDkP from GagagePixel +@since 2025-07-18 +If callback_NotNull is null, target's value is left intact +So, instead of to write the content of this function in-code, +we can just wrote AssignIf(eval(),Varptr(myVar)) +#end +Function AssignIf( callback_NotNull:T(),target:T Ptr ) + Local result:=callback_NotNull() + If result target[0] = result +End + +#rem wonkeydoc @pro Assigns something if not null or false. +@author iDkP from GagagePixel +@since 2025-07-18 +If callback_NotNull is null or false, target's value is left intact +So, instead of to write the content of this function in-code, +we can just wrote AssignIff(eval(),Varptr(myVar)) +#end +Function AssignIff( callback_NotNull:T(),target:T Ptr ) + Local result:=callback_NotNull() + If result And result<>False target[0] = result +End diff --git a/modules/std/syntax/functors/ifelse.wx b/modules/std/syntax/functors/ifelse.wx new file mode 100644 index 00000000..5031f926 --- /dev/null +++ b/modules/std/syntax/functors/ifelse.wx @@ -0,0 +1,29 @@ + +Namespace std.syntax + +#rem monkeydoc @pro It's the ternary but function styled. +@author iDkP from GagagePixel +@since 2025-07-18 +@param eval/state: any values not null +@param callbackTrue/options1 evaluated/stated variable returned if eval/state is not null +@param callbackFalse/options2 evaluated/stated variable returned if eval/state is not null +@return If val is not null/false, returns callbackTrue/option1's value +@return If val is null/false, returns the callbackFalse/option2's value +@example + Local myValue:=IfElse(evalThis,thenDoReturnThat,elseDoReturnThat) +#end +Function IfElse:T( eval:T(),callbackTrue:T(),callbackFalse:T()=Null ) + If eval Return callbackTrue() + Return callbackFalse() +End + +Function IfElse:T( eval:T(),option1:T,option2:T=Null ) + If eval Return option1 + Return option2 +End + +Function IfElse:T( state:T,option1:T,option2:T=Null ) + If eval Return option1 + Return option2 +End + diff --git a/modules/std/syntax/syntax.xw b/modules/std/syntax/syntax.xw index e62ca9ad..ea82bceb 100644 --- a/modules/std/syntax/syntax.xw +++ b/modules/std/syntax/syntax.xw @@ -20,9 +20,11 @@ Namespace std.syntax #Import "funcs/clippers/wraps" #Import "funcs/clippers/frames" -#Import "functors/foreach" #Import "functors/vattribs" #Import "functors/attribs" +#Import "functors/foreach" +#Import "functors/assignif" +#Import "functors/ifelse" #Import "aliases/aliases"