MX2 – stack – lambda

Stack and Lambda to filter values

Namespace myapp
#Import  "<std>"
Using std..

Function Main()
Local stack:=New Stack<Int>
For Local n:=1 To 10
	stack.Push(Rnd(1,100))
Next
stack.Sort()
ShowIt(stack)
'get only value >50
Local stack2:=New Stack<Int>'must be 'visible' outside of Lambda to be used
Local check:=Lambda:Void(minvalue:Int,maxvalue:int)
				For Local x:=Eachin stack
					If x>=minvalue And x<=maxvalue stack2.Push(x)
				Next
				End
	check(30,50) 'calling the filtering

	Print "Filtered Stack is "+stack2.Length
	ShowIt(stack2)
	
End 

Function ShowIt:Int(cnt:Stack<Int>)
	Local counter:Int
	For Local s:=Eachin cnt
		Print counter+" ["+s+"]"
		counter+=1
	Next
	Return 0
End Function

 

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close