Questions tagged [kotlin]

Kotlin is a statically typed programming language that compiles to JVM bytecode, JavaScript, or native binaries.

Filter by
Sorted by
Tagged with
1 vote
1 answer
68 views

Code for working with a tasks in To-Do Android application

Overview I am working on an android To-Do app. I have a piece of code that I use to work with tasks.I am new to android development and want to grow, so I would really like someone to rate my code and ...
Destroyer's user avatar
  • 427
3 votes
1 answer
59 views

Create two teams from a list of players with minimum of one goalkeeper per team

I wanted to create a simple method that creates two random teams for football/soccer match from a list of players with a requirement that the goalkeepers should be in different teams (so that one team ...
qki's user avatar
  • 133
-1 votes
2 answers
79 views

Instantiating Person objects using the builder pattern

I'm trying to make a safe builder using Kotlin that can be partially built and then copied, perhaps multiple times, to avoid repetition. Note that the properties that are reused aren't always the same ...
user's user avatar
  • 499
0 votes
1 answer
75 views

API for general boolean flag set

Very simple question. Imagine are designing library API, where you want to provide way to switch boolean flag. Typically to disable or enable a functionality. For argument's sake, let's say it's ...
K.H.'s user avatar
  • 2,568
0 votes
2 answers
163 views

Iterating through ArchiveInputStream or structures having a 'next'-accessor [closed]

ArchiveInputStream is from apache-commons compress. it is an InputStream. nextEntry is the only method for traversing the stream i've found the while loop is IDE ...
mavriksc's user avatar
  • 111
1 vote
1 answer
63 views

Multi-dimensional arrays exercise: Introduce married couples to each other

Following idea: There are three married couples and they have to be introduced another. I have implemented this solution: ...
michael.zech's user avatar
  • 4,232
8 votes
2 answers
338 views

Constructing a DSL with properties instead of functions, for use in a type-safe pseudo-builder

As one step in a larger builder setup, I need to build a small collection of objects, each with a small number of required attributes, and each of those with a small set of possible values. The actual ...
Mike M.'s user avatar
  • 223
3 votes
0 answers
149 views

Replacing type-check with Visitor in Immutable Event-Sourced Aggregate

In my previous question, one of the answers mentioned that I shouldn't be changing behavior based on the Event class The whole point of classing is that you can get result without having to decide ...
Zymus's user avatar
  • 187
1 vote
0 answers
172 views

Matrix implementation in Kotlin

I put this together for a task and thought some feedback would be useful. ...
OldCurmudgeon's user avatar
2 votes
1 answer
239 views

Using Functional programming to untangle deeply nested loops (Kotlin)

Problem statement for better understanding: Let's say we assign a unique number to each alphabet, a=1, b=2, c=3...z=26 then find the frequency of the sum of each ...
Sid's user avatar
  • 153
3 votes
1 answer
663 views

Aggregate data from a huge list under 50ms

I got this question as a coding challenge and was unable to get it done under 50 milliseconds (my solution takes >100 ms) :D Would you please review my code and share any idea how to do this within ...
David Meik's user avatar
1 vote
0 answers
134 views

Signing in with "Remember me" option implemented with Spring and Kotlin

I'm trying to implement authentication with "Remember me" option using Spring and Kotlin. I would really appriciate if someone could help me find potential issues with that implementation as ...
Weeedooo's user avatar
2 votes
1 answer
222 views

MutableLiveList class for android

I have wrote a MutableLiveList class for android, similar to existing MutableLiveData, but this class instead handles a list and ...
Sourav Kannantha B's user avatar
4 votes
2 answers
554 views

Android Tic-Tac-Toe

I have made an Android Tic-Tac-Toe adaptation as a weekend-project. Here's the Kotlin-code. MainActivity: ...
michael.zech's user avatar
  • 4,232
3 votes
2 answers
387 views

Chess in Kotlin

This is an updated version of my first question: Chess game in Kotlin I wrote the following Chess logic in Kotlin and am looking for feedback to make the code cleaner and follow good software design ...
Florian Walther's user avatar
2 votes
1 answer
628 views

Chess game in Kotlin

I wrote the following Chess logic in Kotlin and am looking for feedback to make the code cleaner and follow good software design principles. I tried to adhere to object-oriented design. Some notes: • ...
Florian Walther's user avatar
2 votes
1 answer
296 views

UDP image livestream from Android device to C# desktop application

After searching a lot, on how to do it and not finding any good solutions, I implemented my own UDP livestream from an Android device to a C#/WPF desktop application. It works, however, since I get ...
Roland Deschain's user avatar
2 votes
1 answer
554 views

A Stateless Immutable Event-Driven DDD Pattern in Kotlin

I've been interested in making fully repeatable, reproducible game states. This led me into the world of DDD, and specifically, the concept of Aggregates + Event Sourcing (although that's not ...
Zymus's user avatar
  • 187
4 votes
2 answers
227 views

Rock-Paper-Scissor-Lizard-Spock in Kotlin

I have made a simple Kotlin application called Rock-Paper-Scissor-Lizard-Spock. The application takes in user input and check if belongs to given set of array. If it belongs then it compares user ...
Kishore kichu's user avatar
2 votes
1 answer
59 views

Linked list that support modifications during iteration

Update: Fixed last item is not removed during iteration Fixed clear() during iteration does nothing Fixed addition of removed item is ignored The lasted code can ...
Ilya Gazman's user avatar
2 votes
1 answer
289 views

Write a Kotlin-function isPrimeNumber

Exercise: Write a prime number-test isPrime(num: Int), which for integer m >= 2 checks, if the integer is a prime number or not. My solution: ...
michael.zech's user avatar
  • 4,232
2 votes
1 answer
41 views

An exercise concering Kotlin Set

Task description: Declare a function twoInThree(a: Set, b: Set, c: Set), which returns the set of all elements, which are contained in exactly two of the three given sets a, b, c. My solution: ...
michael.zech's user avatar
  • 4,232
0 votes
1 answer
69 views

Write a Kotlin function "commonPrefix"

Task description: Write a function commonPrefix, which takes two strings as parameter and returns the common prefix. Example: parameters ...
michael.zech's user avatar
  • 4,232
3 votes
1 answer
59 views

Generating multiplication questions and answers for a quiz style app

See this link for previous post on this subject Generating mathematical questions and answers I have an Android quiz app that I am building to learn kotlin / android app development. Here is an object ...
UnknownError's user avatar
4 votes
2 answers
239 views

Are these Unit tests OK or am I implementing an antipattern or not following best practices

I am testing a Spring boot service using JUnit 5 and Mockito. I haven't spent much time on unit testing in the past so I'm not sure if I'm accidentally implementing an anti-pattern or not following ...
user2094257's user avatar
2 votes
1 answer
142 views

Generating mathematical questions and answers

I have an Android quiz app that I am building to learn kotlin / android app development. Here is an object I have which acts as one of many question builders. Is there a better way of writing this? <...
UnknownError's user avatar
2 votes
1 answer
104 views

Read database from IO context and update UI from Main context in Kotlin

Still a bit new to Kotlin and coroutines, so I want to learn best practices. The following code seems to work as expected in it's original context, though the naming has been tweaked here. The list of ...
steve_79's user avatar
3 votes
1 answer
74 views

Prime number sequence supporting repeated iteration

I'm a long-time Java programmer, but recently I decided to give Kotlin a try. So far, I'm loving the language features, it feels much more expressive than what I'm used to. As practice, I wrote this ...
Kevin K's user avatar
  • 163
2 votes
2 answers
62 views

Composing IHandler<T>

Here is a composable IHandler<T> implementation. Any ideas on how to make it shorter and get rid of exception being thrown? ...
Dmitry Nogin's user avatar
  • 6,133
1 vote
1 answer
63 views

Kotlin fake properties and their usage

I had an idea recently of simplifying some of the code I already have in my Android app that uses Kotlin. I somewhat new to Kotlin, so any opinion would be very appreciated. Before giving you what ...
Vitaliy-T's user avatar
  • 183
4 votes
0 answers
1k views

View Binding with Base Classes

UPDATE: After getting "a kind of" affirmation from various platforms( my discussions on twitter, reddit, other stack overflow posts,etc) I have written an article on this style of view ...
ansh sachdeva's user avatar
2 votes
0 answers
42 views

Which of my string indexing functions in Kotlin is semantically closer to my Java one?

I have a working string indexing method in Java and did convert in Kotlin. All methods shown below produce the same result but as I am really new to the Kotlin language I wanted to ask which of my two ...
PerfLearnling's user avatar
2 votes
0 answers
180 views

2D Array Word Search: Complexity and Optimization

🧩 Objective Determine whether a given word is contained in a 2D Array word search. 🔎 Question 1. What are the time and space complexities of the current algorithm? Time complexity Linear: \$O(2(r * ...
AdamHurwitz's user avatar
0 votes
1 answer
325 views

Generate unique string permutations recursively

🧩 Objective Write a recursive method for generating all permutations of an input string. Return them as a set. See: Recursive String Permutations - Interview Cake 🔎 Questions 1: How does the ...
AdamHurwitz's user avatar
9 votes
2 answers
363 views

Optimize a tile rendering algorithm for Swing Canvas

I have an algorithm that I use to render a text GUI using Swing's Canvas, it looks like this in practice: My goal is to reach 60 frames per second for a full HD ...
Adam Arold's user avatar
1 vote
0 answers
60 views

Basic REST API in Ktor

I have written a basic REST endpoint in Ktor and would like some pointers. Application.kt ...
F.P's user avatar
  • 111
3 votes
1 answer
127 views

Contains all elements and duplicates are taken into account

The idea is to have a function which checks if all elements in a list are contained in another list. But not just the containedness has to be true, but also the times of containedness. One could say ...
michael.zech's user avatar
  • 4,232
4 votes
0 answers
216 views

A better understanding for separation of concerns. Android; Kotlin

I am an Android developer with only 5 months of experience. I am still learning and trying to do my best. Right now I am interested in concept of ...
Vitaliy-T's user avatar
  • 183
4 votes
1 answer
78 views

A Concurrent Tree implementation with consistent snapshot capability

I have a tree in my application from which I need to periodically take a snapshot. I've been using locks so far, but after running into a few deadlock issues I decided to create a lock-free ...
Adam Arold's user avatar
3 votes
1 answer
39 views

How to speed up drawing process of output from .tflite model

I have piece of code where I draw output from model pixel by pixel: ...
SkypeDogg's user avatar
  • 131
1 vote
0 answers
31 views

String tuple serializer

Please review my class which is responsible of serialization and deserialization of the StringTuple data class. ...
Piotr Aleksander Chmielowski's user avatar
4 votes
1 answer
244 views

Representation of data record for an employee (generic method vs design pattern)

preface: I have a part of my code that is repeated more than once and I want to create a generic method or follow a design pattern to make the code cleaner. What I'm trying to achieve is: I have a ...
Remon Shehatta's user avatar
2 votes
2 answers
241 views

Bloomfilter in Kotlin

I would like a code-review. Not so much on if the implementation is good or effecient, it's probably not, more on code style and readability. ...
Peheje's user avatar
  • 119
3 votes
0 answers
933 views

Generic RecyclerView Adapter in Kotlin

I've just finished implementing a Generic RecyclerView adapter in my Android app, written in Kotlin. BaseAdapter.kt: ...
milancodes's user avatar
2 votes
0 answers
209 views

How to implement a single-value cache in RxJava 3?

Kotlin 1.3.+ RxJava 3.0.+ Kotest 4.1.+ ...
Andrey's user avatar
  • 121
9 votes
1 answer
2k views

Arithmetic Parser in Kotlin

I don't really have a problem. But, it's my first time using Kotlin for any project, so I want to know if there is any problem in my code or my code can be made cleaner. This is an arithmetic parser ...
programmer pro's user avatar
5 votes
1 answer
148 views

Double LinkedList Deep Copy in Kotlin with Generics and Thread Safety

Goal Return a deep copy of a double LinkedList. Each node also contains an additional random pointer, potentially to any node or null. Code to start ...
AdamHurwitz's user avatar
3 votes
0 answers
284 views

Game of Life in Kotlin

I've implemented a Game of Life in Kotlin. There are some major requirements on this solution: Purely object-functional production code. As close to an infinite universe as possible. File ...
Christian Hujer's user avatar
3 votes
0 answers
86 views

N-elements byte array to integer conversion (little/big endian and signed/unsigned)

I'm trying to come up with a function to convert byte arrays to their integer representation, using both endianness, and with a signed/unsigned option. ...
LppEdd's user avatar
  • 119
2 votes
1 answer
469 views

Kotlin Stack using an ArrayList to compare and remove elements

Is this a performant strategy to implement a stack in Kotlin to compare and delete values? Expect Create a stack in order to compare an array of asteroids (ASTs) and handle collisions (deletions), ...
AdamHurwitz's user avatar