Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions modules/std/collections/map.wx
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,46 @@ Class Map<K,V>
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<V> )
'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<V> )
'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.
Expand Down
18 changes: 18 additions & 0 deletions modules/std/syntax/funcs/searchin.wx
Original file line number Diff line number Diff line change
@@ -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<K,V>:Int( map:Map<K,V>,key:K,values:Stack<V> )
Return map.Search( key, values.Data )
End

Function SearchIn<K,V>:Int( map:Map<K,V>,key:K,values:V[] )
Return map.Search( key, values )
End

Function SearchIn<K,V>:Int( map:Map<K,V>,key:K,values:List<V> )
Return map.Search( key, values )
End
26 changes: 26 additions & 0 deletions modules/std/syntax/functors/assignif.wx
Original file line number Diff line number Diff line change
@@ -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<T>( 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<T>( callback_NotNull:T(),target:T Ptr )
Local result:=callback_NotNull()
If result And result<>False target[0] = result
End
29 changes: 29 additions & 0 deletions modules/std/syntax/functors/ifelse.wx
Original file line number Diff line number Diff line change
@@ -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>:T( eval:T(),callbackTrue:T(),callbackFalse:T()=Null )
If eval Return callbackTrue()
Return callbackFalse()
End

Function IfElse<T>:T( eval:T(),option1:T,option2:T=Null )
If eval Return option1
Return option2
End

Function IfElse<T>:T( state:T,option1:T,option2:T=Null )
If eval Return option1
Return option2
End

4 changes: 3 additions & 1 deletion modules/std/syntax/syntax.xw
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Loading