@@ -122,11 +122,14 @@ class Lambda {
122122
123123 If `f` is null, the result is unspecified.
124124 **/
125- public static function exists <A >(it : Iterable <A >, f : (item : A ) -> Bool ) {
125+ public static inline function exists <A >(it : Iterable <A >, f : (item : A ) -> Bool ) {
126+ var isExists = false ;
126127 for (x in it )
127- if (f (x ))
128- return true ;
129- return false ;
128+ if (f (x )) {
129+ isExists = true ;
130+ break ;
131+ }
132+ return isExists ;
130133 }
131134
132135 /**
@@ -141,19 +144,22 @@ class Lambda {
141144
142145 If `f` is null, the result is unspecified.
143146 **/
144- public static function foreach <A >(it : Iterable <A >, f : (item : A ) -> Bool ) {
147+ public static inline function foreach <A >(it : Iterable <A >, f : (item : A ) -> Bool ) {
148+ var isAll = true ;
145149 for (x in it )
146- if (! f (x ))
147- return false ;
148- return true ;
150+ if (! f (x )) {
151+ isAll = false ;
152+ break ;
153+ }
154+ return isAll ;
149155 }
150156
151157 /**
152158 Calls `f` on all elements of `it`, in order.
153159
154160 If `f` is null, the result is unspecified.
155161 **/
156- public static function iter <A >(it : Iterable <A >, f : (item : A ) -> Void ) {
162+ public static inline function iter <A >(it : Iterable <A >, f : (item : A ) -> Void ) {
157163 for (x in it )
158164 f (x );
159165 }
@@ -164,7 +170,7 @@ class Lambda {
164170 If `it` is empty, the result is the empty Array even if `f` is null.
165171 Otherwise if `f` is null, the result is unspecified.
166172 **/
167- public static function filter <A >(it : Iterable <A >, f : (item : A ) -> Bool ) {
173+ public static inline function filter <A >(it : Iterable <A >, f : (item : A ) -> Bool ) {
168174 return [for (x in it ) if (f (x )) x ];
169175 }
170176
@@ -180,7 +186,7 @@ class Lambda {
180186
181187 If `it` or `f` are null, the result is unspecified.
182188 **/
183- public static function fold <A , B >(it : Iterable <A >, f : (item : A , result : B ) -> B , first : B ): B {
189+ public static inline function fold <A , B >(it : Iterable <A >, f : (item : A , result : B ) -> B , first : B ): B {
184190 for (x in it )
185191 first = f (x , first );
186192 return first ;
@@ -191,7 +197,7 @@ class Lambda {
191197
192198 If `it` or `f` are null, the result is unspecified.
193199 **/
194- public static function foldi <A , B >(it : Iterable <A >, f : (item : A , result : B , index : Int ) -> B , first : B ): B {
200+ public static inline function foldi <A , B >(it : Iterable <A >, f : (item : A , result : B , index : Int ) -> B , first : B ): B {
195201 var i = 0 ;
196202 for (x in it ) {
197203 first = f (x , first , i );
@@ -206,7 +212,7 @@ class Lambda {
206212
207213 This function traverses all elements.
208214 **/
209- public static function count <A >(it : Iterable <A >, ? pred : (item : A ) -> Bool ) {
215+ public static inline function count <A >(it : Iterable <A >, ? pred : (item : A ) -> Bool ) {
210216 var n = 0 ;
211217 if (pred == null )
212218 for (_ in it )
@@ -252,12 +258,15 @@ class Lambda {
252258
253259 If `f` is null, the result is unspecified.
254260 **/
255- public static function find <T >(it : Iterable <T >, f : (item : T ) -> Bool ): Null <T > {
261+ public static inline function find <T >(it : Iterable <T >, f : (item : T ) -> Bool ): Null <T > {
262+ var first : Null <T > = null ;
256263 for (v in it ) {
257- if (f (v ))
258- return v ;
264+ if (f (v )) {
265+ first = v ;
266+ break ;
267+ }
259268 }
260- return null ;
269+ return first ;
261270 }
262271
263272 /**
0 commit comments