Skip to content

Instantly share code, notes, and snippets.

View devboy's full-sized avatar

Dominic Graefen devboy

View GitHub Profile
using org.devboy.ArrayUtils;
var is_c = function(x) { return x == "c"; }
[ "a", "b", "c" ].delete_if( is_c ); // returns [ "a", "b" ]
import org.devboy.ArrayUtils;
var is_c = function(x) { return x == "c"; }
ArrayUtils.delete_if( [ "a", "b", "c" ], is_c ); // returns [ "a", "b" ]
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) )
doMath( 10, 2, callback( swapDivide, true ) ); // return 0.2
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
function sumOfFloats( x: Float, y: Float, z: Float ) {
return x + y + z;
}
var addFloatToOneAndTwo = callback( sumOfFloats, 1, 2 );
addFloatToOneAndTwo( 5 ); // returns 8
function add( x: Float, y: Float ) {
return x + y;
}
var addOne = callback( add, 1 );
addOne( 5 ); // returns 6
function add( x: Float, y: Float ) {
return x + y;
}
function addOne( x: Float ) {
return add( 1, x );
}
function add( x: Float, y: Float ) {
return x + y;
}
function addOne( x: Float ) {
return add( 1, x );
}
function array_delete_if( array: Array<Dynamic>, processor: Dynamic-> Bool ):Array<Dynamic>
{
for ( item in array )
if ( processor(item) )
array.remove( item );
return array;
}