This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using org.devboy.ArrayUtils; | |
| var is_c = function(x) { return x == "c"; } | |
| [ "a", "b", "c" ].delete_if( is_c ); // returns [ "a", "b" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.devboy.ArrayUtils; | |
| var is_c = function(x) { return x == "c"; } | |
| ArrayUtils.delete_if( [ "a", "b", "c" ], is_c ); // returns [ "a", "b" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.devboy; | |
| class ArrayUtils | |
| { | |
| public static function delete_if<T>( array: Array<T>, processor: T -> Bool ): Array<T> | |
| { | |
| var remove: Array<T> = []; | |
| for ( item in array ) | |
| if ( processor(item) ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| doMath( 10, 2, callback( swapDivide, true ) ); // return 0.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function doMath( x: Float, y: Float, operation: Float -> Float -> Float ) { | |
| return operation( x, y ); | |
| } | |
| function swapDivide( swap: Bool, x: Float, y: Float ) { | |
| return swap ? y / x : x / y; | |
| } | |
| doMath( 10, 2, function(x, y) { return swapDivide(true, x, y); } ); // returns 0.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sumOfFloats( x: Float, y: Float, z: Float ) { | |
| return x + y + z; | |
| } | |
| var addFloatToOneAndTwo = callback( sumOfFloats, 1, 2 ); | |
| addFloatToOneAndTwo( 5 ); // returns 8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function add( x: Float, y: Float ) { | |
| return x + y; | |
| } | |
| var addOne = callback( add, 1 ); | |
| addOne( 5 ); // returns 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function add( x: Float, y: Float ) { | |
| return x + y; | |
| } | |
| function addOne( x: Float ) { | |
| return add( 1, x ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function add( x: Float, y: Float ) { | |
| return x + y; | |
| } | |
| function addOne( x: Float ) { | |
| return add( 1, x ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function array_delete_if( array: Array<Dynamic>, processor: Dynamic-> Bool ):Array<Dynamic> | |
| { | |
| for ( item in array ) | |
| if ( processor(item) ) | |
| array.remove( item ); | |
| return array; | |
| } |