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
0answers
11 views

Iterative Fibonacci number generator in Kotlin

I have very limited experience in Java and slightly more in C# (just doing Advent of Code problems last month), so I'm not familiar with how to write idiomatic Kotlin. This class implements an ...
1
vote
0answers
25 views

Calculator App with Kotlin and Android Studio

Hello I am an absolute beginner with Kotlin and Android Studio. I want to hear what I could do better for the next time or any flaws my code has. The code implements a four-function calculator (+ - ✕ ÷...
1
vote
0answers
19 views

Kotlin AsyncPriorityQueue

Unbounded threadsafe suspending priority queue Items are ordered by an integer priority value passed into the enqueue() method dequeue() retrieves and removes the head of the queue or suspends until ...
2
votes
2answers
37 views

commandline Password-Generator in Kotlin

So I (a newbie to programming) wrote this password-generator as one of my very first programs in Kotlin. I started with Java a few weeks ago. I soon realized that Java was too hard for me, so I ...
1
vote
0answers
32 views

Android BMI calculator using LiveData

I have made a Body mass index-calculator using ViewModel and LiveData. Source-code of the MainActivity: ...
0
votes
0answers
25 views

Implementing a persistent Firestore event listener with Kotlin flows

I was writing a social media sample application for Android in Kotlin. One of the requirements in the project is a screen which show the profile of his friend to a user. This profile screen should ...
3
votes
1answer
38 views

Fragment to control and show camera images

I have never tried this before. Just started with Kotlin and Android CameraX. Here is a fragment I would like some feedback on so I can writer safer and better Kotlin code. ...
0
votes
0answers
15 views

Reactive Spring Cloud Stream WebSocket Source Service

This was the first time I dipped my toes into Spring Cloud Stream in combination with reactive programming via a reactive WebSocket client. It works in terms of general functionality - A subscriber to ...
2
votes
1answer
66 views

Merging and sorting queue/list implementation

My requirement is implementing a Queue<T> (where T is a Lexeme) that is capable of ...
0
votes
0answers
10 views

Firestore Paging implementation for multiple OR query Android

As firestore don't support in operation for more than 10 items. So I decided to write a code to handle multiple (OR) query and merge them afterwards. Suppose I want to show posts of the user you ...
0
votes
1answer
35 views

Android user input validation

I have made a tiny Android-project to familiarize myself with user input validation. The app just has an EditText-control for user input, a button "Compute Result" and a TextView, which ...
1
vote
1answer
74 views

Cleaning Kotlin method which returns the document name after the id

I'm just getting to know the possibilities of Kotlin and mongoDB. I am writing a method that returns the name of the street after the ID. Everything works, but I find it quite sloppy. Empty String ...
0
votes
0answers
32 views

Code to plot chart with data

I am working on a program that the user can use to track the parameters of his body (such as weight, waist size). I have a code that builds a chart based on these data. I would like to hear criticism ...
0
votes
2answers
77 views

LeetCode 05 with Manacher's algorithm

I finished LeetCode 05 with simplified (for ease of implementation) Manacher's algorithm. IMHO it should keeps \$\mathcal{O}(n)\$ time and space complexity. However, LeetCode's benchmark ranked my ...
1
vote
1answer
55 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 ...
3
votes
1answer
47 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 ...
-1
votes
2answers
71 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 ...
0
votes
1answer
46 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 ...
0
votes
2answers
58 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 ...
1
vote
1answer
56 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: ...
7
votes
2answers
265 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 ...
3
votes
0answers
136 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 ...
0
votes
1answer
66 views

Kotlin extension function in dto vs pojo dto in hexagonal architecture

from kotlin page we can read: In particular, when defining extension functions for a class which are relevant for all clients of this class, put them in the same file with the class itself. When ...
1
vote
0answers
41 views

Matrix implementation in Kotlin

I put this together for a task and thought some feedback would be useful. ...
2
votes
1answer
70 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 ...
2
votes
1answer
325 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 ...
1
vote
0answers
78 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 ...
1
vote
1answer
75 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 ...
2
votes
2answers
119 views

Android Tic-Tac-Toe

I have made an Android Tic-Tac-Toe adaptation as a weekend-project. Here's the Kotlin-code. MainActivity: ...
0
votes
1answer
185 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 ...
1
vote
1answer
176 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: • ...
1
vote
1answer
76 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 ...
2
votes
1answer
319 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 ...
4
votes
2answers
72 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 ...
2
votes
1answer
43 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 ...
2
votes
1answer
208 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: ...
2
votes
1answer
33 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: ...
0
votes
1answer
49 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 ...
0
votes
0answers
25 views

Best practice to change item based on RoomDB value before inserting it using Kotlin

In my App i use Room database and i have three tables where two of them are connected. The app just save the user input and insert it in the database. The user actually just insert as input a code and ...
2
votes
1answer
48 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 ...
4
votes
2answers
165 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 ...
1
vote
1answer
100 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? <...
3
votes
1answer
38 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 ...
3
votes
1answer
61 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 ...
2
votes
2answers
58 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? ...
1
vote
1answer
44 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 ...
3
votes
0answers
850 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 ...
2
votes
0answers
37 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 ...
2
votes
0answers
125 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 * ...
0
votes
1answer
184 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 ...

1
2 3 4 5