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
| var ints = [1, 2, 3] | |
| var strings = ["a", "bb", "ccc"]; | |
| var biggerThan1 = function(x:Int) { | |
| return x > 1; | |
| } | |
| var longerThan1 = function(x:String) { | |
| return x.length > 1; | |
| } |
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, mathOperation: Float -> Float -> Float ) { | |
| return mathOperation(x, y); | |
| } | |
| var addition = function(x: Float, y: Float) { | |
| return x + y; | |
| } | |
| var square = function(x: Float) { | |
| return x * 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
| var biggerThan2: Int -> Bool = function(x) { | |
| return x > 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
| var getStringXTimes = function(x: Int, string: String) { | |
| var result = ""; | |
| for ( i in 0...x ) | |
| result += string; | |
| return result; | |
| } | |
| type(getStringXTimes); // Int -> String -> String |
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
| var square = function(x: Float) { | |
| return x * x; | |
| } | |
| type(square); // type of square is Float -> Float |
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 square( x: Float ) { | |
| return x * 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 inferred(x) { | |
| return x; | |
| } | |
| inferred("abc"); // will take the string and return it | |
| inferred(1); // will throw a compiler error because x is typed to String now |
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
| var x: String; // type is now set to String | |
| x = "I'm a String"; // this will work | |
| x = 1; // this will cause an error |
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
| var x; // type of x is Unknown | |
| x = "I'm a String"; // type of x is set to String | |
| x = 1; // this will cause a compiler error as Int cannot be assigned to String |
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
| static inline function array_delete_if<T>( array: Array<T>, processor: T -> Bool ):Array<T> | |
| { | |
| for ( item in array ) | |
| if ( processor(item) ) | |
| array.remove( item ); | |
| return array; | |
| } |