@@ -903,4 +903,84 @@ Class Stack<T> Implements IContainer<T>
903903 Sort( compare, x, hi, filter )
904904 End
905905
906+ #rem wonkeydoc Iterates through a container and checks if every item fulfills the predicate.
907+ #end
908+ Method AllIt:Bool( fun:Bool( it:T ) )
909+
910+ DebugAssert( _length, "Stack is empty" )
911+
912+ For Local i := 0 Until _length
913+ If Not fun( _data[i] ) Return False
914+ Next
915+ Return True
916+ End
917+
918+ #rem wonkeydoc Iterates through a container and checks if at least one item fulfills the predicate.
919+ #end
920+ Method AnyIt:Bool( fun:Bool( it:T ) )
921+
922+ DebugAssert( _length, "Stack is empty" )
923+
924+ For Local i := 0 Until _length
925+ If fun( _data[i] ) Return True
926+ Next
927+ Return False
928+ End
929+
930+ #rem wonkeydoc Returns a new Array with the results of the op func applied to every item in the stack.
931+ #end
932+ Method MapIt<M>:M[]( fun:M( it:T ) )
933+
934+ DebugAssert( _length, "Stack is empty" )
935+
936+ Local mm := New M[_length]
937+ For Local i := 0 Until _length
938+ mm[i] = fun( _data[i] )
939+ Next
940+ Return mm
941+ End
942+
943+ #rem wonkeydoc Returns a new Array with all the items of stack that fulfill the predicate func.
944+ #end
945+ Method FilterIt:T[]( fun:Bool( it:T ) )
946+
947+ DebugAssert( _length, "Stack is empty" )
948+
949+ Local mm := New T[_length]
950+ Local idx := 0
951+ For Local i := 0 Until _length
952+ If fun( _data[i] )
953+ mm[idx] = _data[i]
954+ idx += 1
955+ Endif
956+ Next
957+ Return mm.Slice( 0, idx )
958+ End
959+
960+ #rem wonkeydoc Fold a sequence from left to right, returning the accumulation.
961+ #end
962+ Method FoldItl:T( fun:T( a:T, b:T ) )
963+
964+ DebugAssert( _length, "Stack is empty" )
965+
966+ Local result:T = _data[0]
967+ For Local i := 1 Until _length
968+ result = fun( result, _data[i] )
969+ Next
970+ Return result
971+ End
972+
973+ #rem wonkeydoc Fold a sequence from right to left, returning the accumulation.
974+ #end
975+ Method FoldItr:T( fun:T( a:T, b:T ) )
976+
977+ DebugAssert( _length, "Stack is empty" )
978+
979+ Local result:T = _data[_length - 1]
980+ For Local i := _length - 2 To 0 Step -1
981+ result = fun( result, _data[i] )
982+ Next
983+ Return result
984+ End
985+
906986End
0 commit comments