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
0 votes
1 answer
42 views

Adapter pattern apply with JsonObject

The purpose of the code is to apply adapter pattern to put an extra feature for searching through json object. I hate deep nested json object because it makes my code look messy when access through ...
user avatar
  • 271
6 votes
3 answers
216 views

Produce an arithmetic progression

I have made a function which takes in an end point and a step, then produces a list of integers with the step in mind. For example, if the end point is 10 and the step is 2, the function should return ...
user avatar
-3 votes
1 answer
51 views

Kotlin, calculate fingerprint from public key

I created function for calculating fingerprint from a public key ...
user avatar
1 vote
2 answers
32 views

Performing complex operation before calling the primary constructor in Kotlin

Semester is a simple enum class. ...
user avatar
1 vote
1 answer
56 views

Getting a single result from multiple LiveData objects

I have an Android viewmodel for a Fragment that requires the user to perform multiple tasks. In addition to a LiveData object to track the status of each task, I ...
user avatar
2 votes
1 answer
48 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 ...
user avatar
3 votes
1 answer
150 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 (+ - ✕ ÷...
user avatar
1 vote
0 answers
50 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 ...
user avatar
2 votes
2 answers
70 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 ...
user avatar
2 votes
0 answers
68 views

Android BMI calculator using LiveData

I have made a Body mass index-calculator using ViewModel and LiveData. Source-code of the MainActivity: ...
user avatar
  • 3,758
0 votes
0 answers
78 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 ...
user avatar
3 votes
1 answer
101 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. ...
user avatar
  • 169
0 votes
0 answers
22 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 ...
user avatar
  • 201
2 votes
1 answer
69 views

Merging and sorting queue/list implementation

My requirement is implementing a Queue<T> (where T is a Lexeme) that is capable of ...
user avatar
  • 121
0 votes
0 answers
15 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 ...
user avatar
0 votes
1 answer
49 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 ...
user avatar
  • 3,758
1 vote
1 answer
80 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 ...
user avatar
  • 35
0 votes
0 answers
35 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 ...
user avatar
  • 407
0 votes
2 answers
80 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 ...
user avatar
1 vote
1 answer
57 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 ...
user avatar
  • 407
3 votes
1 answer
50 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 ...
user avatar
  • 133
-1 votes
2 answers
74 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 avatar
  • 499
0 votes
1 answer
50 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 ...
user avatar
  • 1,330
0 votes
2 answers
68 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 ...
user avatar
  • 111
1 vote
1 answer
57 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: ...
user avatar
  • 3,758
7 votes
2 answers
279 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 ...
user avatar
  • 203
3 votes
0 answers
138 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 ...
user avatar
  • 187
1 vote
0 answers
63 views

Matrix implementation in Kotlin

I put this together for a task and thought some feedback would be useful. ...
user avatar
2 votes
1 answer
128 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 ...
user avatar
  • 153
3 votes
1 answer
419 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 ...
user avatar
1 vote
0 answers
83 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 ...
user avatar
1 vote
1 answer
114 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 ...
user avatar
3 votes
2 answers
177 views

Android Tic-Tac-Toe

I have made an Android Tic-Tac-Toe adaptation as a weekend-project. Here's the Kotlin-code. MainActivity: ...
user avatar
  • 3,758
1 vote
1 answer
231 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 ...
user avatar
1 vote
1 answer
266 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: • ...
user avatar
1 vote
1 answer
121 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 ...
user avatar
2 votes
1 answer
375 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 ...
user avatar
  • 187
4 votes
2 answers
99 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 ...
user avatar
2 votes
1 answer
49 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 ...
user avatar
2 votes
1 answer
217 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: ...
user avatar
  • 3,758
2 votes
1 answer
35 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: ...
user avatar
  • 3,758
0 votes
1 answer
55 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 ...
user avatar
  • 3,758
2 votes
1 answer
51 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 ...
user avatar
4 votes
2 answers
173 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 ...
user avatar
1 vote
1 answer
115 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? <...
user avatar
3 votes
1 answer
50 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 ...
user avatar
3 votes
1 answer
63 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 ...
user avatar
  • 163
2 votes
2 answers
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? ...
user avatar
  • 6,123
1 vote
1 answer
45 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 ...
user avatar
  • 173
3 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 ...
user avatar

1
2 3 4 5