Questions tagged [kotlin]
Kotlin is a statically typed programming language that compiles to JVM bytecode, JavaScript, or native binaries.
258
questions
0
votes
1
answer
3k
views
Kotlin text validation
I'm new to Kotlin, not so new to Java and Android development. But willing and trying to ...
6
votes
1
answer
731
views
TODO app in Kotlin
I'm learning Kotlin and I made a todo program (in command line) with Kotlin and Maven as my build tool.
Full project.
Description
The idea of my program is to read a file (path defined in a config ...
6
votes
1
answer
326
views
Kotlin sieve using sequences
While learning about functional programming the simple sieve example was brought up in Haskell. I wanted to try a Kotlin implementation using sequences.
Are there any other quick wins without ...
0
votes
1
answer
82
views
Repository layer for MongoDB
I've implemented a quick and dirty repository to save and insert users to a MongoDB. As you can see, it just inserts one and finds one. Not a rocket.
The thing is I don't really know what are the ...
2
votes
0
answers
133
views
Knuth Morris Pratt substring search algorithm
Below you can find a Kotlin based implementation of the Knuth-Morris-Pratt substring search algorithm.
...
1
vote
1
answer
4k
views
Simple function that execute an instruction every X time until Y condition is accomplished
What do you think about this implementation?
...
3
votes
2
answers
3k
views
Kotlin function which counts standard deviation
Here is the code. The code should counts the standard deviation for double array, but also for Int arrays.
...
1
vote
1
answer
63
views
How to make my save/load to/from file function more canonical?
I started to learn Kotlin and am now looking for common ways to save object to file and then load an object from a file. In my case, I am saving ...
1
vote
0
answers
314
views
My first use of RX-java with Kotlin and vertx
I extracted a small part of my project, it is a workflow engine based on vertx rx-java and Kotlin. This part represent the code use to manage Bpmn Service task. The workflow is a stack of ServiceTask ...
4
votes
1
answer
861
views
Red Black Tree Implementation in Kotlin
I know that there are enough Red Black Tree implementations in the Java libraries, like e.g. java.util.TreeMap. Yet I wanted to create my own for learning purposes ...
0
votes
1
answer
54
views
Function to obtain BluetoothNameId from an identifier
I have a class which is looking like this:
...
3
votes
0
answers
266
views
Search GitHub users when text field changes in Kotlin Android app
Problem: Search for users by their name using the GitHub API (sorted by the number of followers) and display the results in a RecyclerView.
Implementation: Hitting the GitHub API every time when user ...
2
votes
1
answer
654
views
Word Chain Solver
"Write a program that solves word-chain puzzles.
The challenge is to build a chain of words, starting with one particular word and ending with another. Successive entries must all be real words, and ...
0
votes
1
answer
2k
views
Remove repetitive code for multiple spinners using one listener
I managed to setup multiple spinners using one listener but there is a lot of repetition in the code.
My full onItemSelected method:
...
0
votes
1
answer
2k
views
Loop to check isNullOrEmpty then setVisibility & setText
My code below is working fine but I know it can be done more efficiently using a loop.
I'm checking the VAL (such as description, ingredient2, etc.) which are Strings from my SQL lite Db to see if ...
3
votes
3
answers
128
views
Word = smallWord1 + smallWord2
Look for all six letter words which are composed of two concatenated smaller words.
Please give me feedback regarding good coding standards.
...
2
votes
1
answer
2k
views
Minimum Priority Queue implementation in Kotlin
Below you can find a generic implementation and some unit tests of a minimum priority queue in Kotlin.
What could be improved in this implementation, so that it complies to best coding practices in ...
4
votes
1
answer
2k
views
Number-guessing game in Kotlin
I am a Java developer, and I recently gave Kotlin a try.
To begin, I did a little exercise I often do when I start a new language, to verify I got the very basics: the more or less game.
The code I ...
1
vote
4
answers
365
views
Anagram Generator
This is a program that takes lines from 'wordList' and prints it's anagrams, found in the dictionary.
Please give me feedback regarding good coding practices.
...
2
votes
2
answers
219
views
Finding football team with the smallest difference in goals
The file football.dat contains the results from the English Premier League for 2001/2. The columns labeled ‘F’ and ‘A’ contain the total number of goals scored for and against each team in that season ...
3
votes
2
answers
85
views
Binary Search, using .remove
I'm aware that a function in the standard library exists. Please give me feedback regarding good coding conventions and standards.
...
3
votes
2
answers
134
views
Horner's rule for polynomial evaluation
Any better ways to implement 'inverseIndices'? Please give me feedback regarding good coding conventions.
...
1
vote
3
answers
73
views
Mersenne Prime Oracle
Please give me any feedback regarding good coding standards and readability.
...
3
votes
2
answers
150
views
Trying to Store EditText Values in SharedPrefs using a Single addTextChangedListener
The code is completely functional but I'd rather not call two functions when I know it can be done more efficiently. My goal is to store EditText values in SharedPrefs using a single ...
4
votes
2
answers
533
views
Storing realm objects using Kotlin extensions
I am a Java Android Developer and I'm approaching Kotlin.
I have defined the following class:
open class Player : RealmObject() {
...
}
And I defined the ...
3
votes
2
answers
1k
views
Damerau Levenshtein Implementation in Kotlin
This is an implementation of the Damerau-Levenshtein distance in Kotlin which I created as an exercise, but might be also useful, if it proves to be correct.
The implementation is based on this ...
3
votes
2
answers
1k
views
Merge Sort in Kotlin
I started learning kotlin recently,with some background in java.
So I wrote a merge sort algorithm in kotlin.
I am looking for best practices in kotlin and looking for this code review.
I also ...
2
votes
1
answer
115
views
Improvements for ugly reflection
I have a project that uses a library to save serialized objects in items and loads them again, when needed.
To do the de-/serialization, this library uses Gson.
Due to how Gson works and how the ...
2
votes
2
answers
179
views
Calculate the time it takes to achieve your money goal in Kotlin
I am writing a very simple test application in Kotlin for Android, where I just want to calculate the time it takes for someone to reach a specific amount of money, taking into count his salary and ...
8
votes
3
answers
10k
views
Kotlin: Comparing enums
I am currently converting a project from Java to kotlin and re-writing the code in the process to make the most out of kotlin's capabilities. The project contains a Battle System which uses elements ...
4
votes
0
answers
287
views
Trying to avoid null types using lazy and lateinit Kotlin
I am using Kotlin from quite some time now, but I could not able to achieve not-null types for all the properties in Kotlin.
After what I learned by watching Kotlin in Google IO and a bit of research,...
2
votes
3
answers
121
views
Message class, with constructors for data from user and from database
I'm fairly new to Kotlin, and am looking to slim down a data class.
It has two constructors, one for creation based on user input, and one for creation based on database data.
...
1
vote
0
answers
412
views
Generating ANTLR fragments for unicode identifier rules
The Unicode Consortium has actually defined a specification for
the provision of a parsing and/or lexing engine for identifiers, such as programming language variables or domain names.
(Unicode® ...
3
votes
0
answers
151
views
BDD on Android with Kotlin
I am considering an approach fo BDD tests on Android.
The sample app — a simple messenger — has been made in Kotlin, so will be the tests.
I ended up with something like this :
...
5
votes
2
answers
3k
views
Java/Kotlin JSON parsing improvement
I consume an API which gives me this type of JSON:
...
4
votes
2
answers
4k
views
Observer pattern using a set of observers and delegated properties
The idea is to implement the observer pattern, with a separate notification method for each observed property of the observed object. Let me start with a simplified use case:
...
3
votes
0
answers
1k
views
Kotlin fuzzy matching
This is a pseudo-follow up to Kotlin Data Class Wildcard: taking in advice from that question I came upon a better but quite different solution to the same problem.
The problem: fuzzy matching AST ...
2
votes
1
answer
1k
views
Redis protocol implementation by Kotlin
I have created my first project on the github. It is Redis client protocol implementation (request-responce part only). I would like to make my sources more Kotlin style. Please, check my sources and ...
3
votes
1
answer
340
views
Kotlin Data Class Wildcard
I'm writing a small custom DSL and interpreter as an exercise in understanding how the language stack (lexer/parser/(interpreter/compiler)) works. Because I want to be able to report the location of ...
3
votes
1
answer
1k
views
LeetCode: Add Two Numbers (in Kotlin)
(...as I still learning Kotlin) I found this "problem":
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain ...
5
votes
2
answers
239
views
Return the indices of the two numbers such that they add up to a specific target
(...as I learn Kotlin) I want to get the indices of the two numbers such that they add up to a specific target from a given array of integers.
Solution:
...
5
votes
1
answer
500
views
Christmas Tree in Kotlin
Please review my code for printing a Christmas Tree.
The idea was to merge some functional programming ideas (immutability, streams) and OOP (every thing is a small object).
I'm looking for a review ...
7
votes
1
answer
209
views
Reduce amount of calls to database for authentication
I'm currently having a bit of code, which I just know can be improved a lot. I am just blind to it. All of my code looks quite neat to me, except these parts... The login + authentication process is ...
10
votes
1
answer
8k
views
Event-driven finite state machine DSL in Kotlin
I wrote a DSL for defining a finite state machine. My robotics team wants to use a state machine to manage the state of the subsystems on our robot, like the arms, drive train, lifter, etc. Each ...
5
votes
2
answers
977
views
Maximise adjacent numbers in a functional style (PE#11)
What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the [provided] 20×20 grid? [source]
This solution works, and works effectively ...
3
votes
0
answers
302
views
Console command parser for my custom Libgdx console (gamedev)
For a game I'm writing using LibGDX framework and Kotlin language, I've decided to make a dev console. This is a WIP line parser. Since there's already a decent amount of code written I've decided to ...
5
votes
1
answer
990
views
Credit card / IMEI check digit in Kotlin
I recently had the need to implement Luhn's Algorithm in a Java/Kotlin application. I needed a function that would add the check digit to the string of a number like a credit card or IMEI. It could be ...
3
votes
2
answers
460
views
Postponed Prime Sequence in Kotlin
Following my previous unbounded prime generator and a followup by Martin R, I've tested the waters in Kotlin by making an unbounded sieve.
To quote Martin R's wonderful explanation of the base ...
3
votes
0
answers
1k
views
Roman number converter in Kotlin
I'm learning kotlin and java. As a code-kata I wrote the roman to decimal converter. I'd be very grateful for code review.
I was trying to keep things simple and funcional. I'd especially appreciate ...
2
votes
1
answer
6k
views
Counter with increment and decrement buttons
For my first Kotlin project, I'm implementing the Redux pattern with simple Increment and Decrement buttons and a text view to display the current value.
My main questions have to do with Kotlin and ...