Last active
March 22, 2022 08:32
-
-
Save Farhandroid/36b2363e90d6ac3c995877ef98a5b058 to your computer and use it in GitHub Desktop.
Search
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
| class SearchUtil(private val list: List<Int>) { | |
| fun searchItem(element: Int, foundItem: (element: Int?) -> Unit) { | |
| val itemFoundList = list.filter { | |
| it == element | |
| } | |
| if (itemFoundList.isNullOrEmpty()) | |
| foundItem(null) | |
| else | |
| foundItem(itemFoundList.first()) | |
| } | |
| } | |
| fun search() { | |
| val searchUtil = SearchUtil(listOf(25, 46, 35)) | |
| searchUtil.searchItem(element = 25) { | |
| println("Search result : $it") | |
| } | |
| } | |
| fun main() { | |
| search() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment