Building our app
We will be building a command-line based CSV reader that prints the unique entries of the columns and their counts, based on user input in Kotlin Native.
Writing the main function
Kotlin Native has the same language syntax and includes the standard library. Hence, the main
function in Kotlin Native looks the same as the main
function in JVM or JS. It is similar to the following syntax:
// Starting point fun main(args: Array<String>) { // Rest of code over here.. }
The main
function takes args
, which contains the arguments from the command line.
Reading command-line arguments
We will be taking two arguments from the command line:
- The name of the CSV file to read
- The column number to find unique entries from
The following code block shows how to read arguments passed from the command line:
// Get command line input if (args.size != 2) { println("Usage: csv_filename column_number") return } val fileName = args[0] val columnNumber...