Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kotlin I/O operations to fix #736 #762

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
270 changes: 270 additions & 0 deletions web/thesauruses/kotlin/1.5/io.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
{
"meta": {
"language": "kotlin",
"language_name": "Kotlin",
"structure": "io",
"language_version": "1.5"
},
"concepts": {
"write_line": {
"code": [
"print(\"...\")"
]
},
"write_line_with_new_line": {
"code": [
"println(\"...\")"
]
},
"read_line": {
"code": [
"val variable_name = readln()"
]
},
"read_char": {
"code": [
"val variable_name = readln()",
"val first_char = variable_name[0]"
],
"comment": [
"First character can be read by accessing the first element of the string"
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I've tried to keep the best practice that if you're writing code to replicate a function that doesn't exist, it shouldn't be in here. So if there's no built-in way to do that, it should probably be not-implemented: true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has been changed to:

image

},
"clear_console_output": {
"not-implemented": true
},
"change_console_background_color": {
"not-implemented": true
},
"change_console_text_color": {
"not-implemented": true
},
"file_functions_lib": {
"code": [
"java.io.File"
]
},
"list_directory": {
"code": [
"val dir = File(\".\")",
"val files = dir.listFiles()",
"file?.forEach { println(it.name) }"
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, as a reference tool, this should probably be just dir.listFiles or like File(".").listFiles() to show the form of how it works, not the full example.

(Similar to others below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has been changed to:

image

},
"read_directory_info": {
"code": [
"val dir = File(\".\")",
"val files = dir.listFiles()",
"println(\"Number of items: ${files.size}\")",
"println(\"Total size: ${files.sumOf { it.length() }}\")"
],
"comment": [
"There are no in built stats functions in Kotlin, so we have to calculate them manually"
]
},
"create_directory": {
"code": [
"File(\"location\").mkdir()"
],
"comment": [
"Successful creation can be checked with conditional statements"
]
},
"delete_directory": {
"code": [
"File(\"location\").delete()"
]
},
"rename_directory": {
"code": [
"File(\"oldDirectoryName\").renameTo(File(\"newDirectoryName\"))"
]
},
"move_directory": {
"code": [
"File(\"oldDirectoryName\").renameTo(File(\"newDirectoryName\"))"
]
},
"update_directory_permissions": {
"code": [
"File(\"location\").setReadable(true, true).setWritable(true, true)"
],
"comment": [
"First parameter: specifies if permission is granted (true) or revoked (false)\n\n Second parameter: specifies if permission is granted to all users (true) or only the owner (false)"
]
},
"read_line_of_file": {
"code": [
"val line = File(\"filePath\").bufferedReader().readLine()"
]
},
"read_lines_of_file": {
"code": [
"val lines = File(\"filePath\").readLines()"
]
},
"read_file_stream": {
"code": [
"val inputStream = File(\"filePath\").inputStream()",
"// OR",
"File(\"filePath\").inputStream().use { inputStream ->",
"// Code to alter stream",
"}"
],
"comment": [
"The second example ensures the stream is closed after use"
]
},
"create_file": {
"code": [
"val fileCreated = File(\"filePath\").createNewFile()"
]
},
"delete_file": {
"code": [
"val fileDeleted = File(\"filePath\").delete()"
]
},
"update_file": {
"code": [
"val lines = File(\"filePath\").readLines().toMutableList()",
"lines.add(\"Example text\")",
"File(filePath).writeText(lines.joinToString(\"\\n\"))"
],
"comment": [
"This example appends a line to the end of the file, there is no explicit update method present in this language"
]
},
"move_file": {
"code": [
"val moved = File(\"sourceFilePath\").renameTo(File(\"targetFilePath\"))"
]
},
"network_functions_lib": {
"not-implemented": true
},
"send_a_http_request": {
"not-implemented": true
},
"send_a_get_request": {
"not-implemented": true
},
"send_a_post_request": {
"not-implemented": true
},
"send_a_put_request": {
"not-implemented": true
},
"send_a_patch_request": {
"not-implemented": true
},
"send_a_delete_request": {
"not-implemented": true
},
"send_a_head_request": {
"not-implemented": true
},
"send_a_options_request": {
"not-implemented": true
},
"send_a_connect_request": {
"not-implemented": true
},
"send_a_trace_request": {
"not-implemented": true
},
"add_headers": {
"not-implemented": true
},
"add_query_params": {
"not-implemented": true
},
"inbuilt_url_class": {
"not-implemented": true
},
"open_a_socket": {
"not-implemented": true
},
"close_a_socket": {
"not-implemented": true
},
"add_authorization_headers": {
"not-implemented": true
},
"add_cookies": {
"not-implemented": true
},
"read_cookies": {
"not-implemented": true
},
"read_headers": {
"not-implemented": true
},
"database_functions_lib": {
"not-implemented": true
},
"open_connection": {
"not-implemented": true
},
"close_connection": {
"not-implemented": true
},
"execute_query_single_result_set": {
"not-implemented": true
},
"execute_query_multiple_result_sets": {
"not-implemented": true
},
"execute_non_query": {
"not-implemented": true
},
"json_function_lib": {
"not-implemented": true
},
"serialize_json": {
"not-implemented": true
},
"deserialize_json": {
"not-implemented": true
},
"serialize_json_with_options": {
"not-implemented": true
},
"deserialize_json_with_options": {
"not-implemented": true
},
"xml_function_lib": {
"not-implemented": true
},
"serialize_xml": {
"not-implemented": true
},
"deserialize_xml": {
"not-implemented": true
},
"serialize_xml_with_options": {
"not-implemented": true
},
"deserialize_xml_with_options": {
"not-implemented": true
},
"csv_function_lib": {
"not-implemented": true
},
"read_csv_file": {
"not-implemented": true
},
"read_csv_to_type": {
"not-implemented": true
},
"write_csv_file": {
"not-implemented": true
},
"append_csv_file": {
"not-implemented": true
},
"set_csv_delimiter": {
"not-implemented": true
}
}
}
Loading