Created
December 2, 2018 05:21
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 com.dav.vendator; | |
//Author: Dav Vendator | |
/* | |
Code for Kotlin: Higher Order Functions, Lambdas and Extension methods | |
posted at: https://streamofbytes.blogspot.com | |
*/ | |
fun simpleFun() = println("Hello World") | |
fun returnFun(mul: Int): (arg: Int) -> Int{ | |
return fun (arg: Int) = arg * mul | |
} | |
//typealias is like typedef in C/C++ | |
typealias stringPredicate = (str: String) -> Boolean | |
//Filter list based on predicate | |
fun takeFun(pred: stringPredicate, list: ArrayList<String>): ArrayList<String>{ | |
return ArrayList(list.filter { pred(it) }) | |
} | |
fun main(){ | |
simpleFun() | |
val newFun = returnFun(23) | |
println("${2} mutliplied by ${23} is ${newFun(2)}") | |
val filteredList = takeFun({ | |
it.endsWith("php") | |
}, arrayListOf("https://helloworld.aspx", "https://streamofbytes.php", "1234")) | |
println("All the url's ending with *.php ${filteredList}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment