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

Handling View State & Side Effects with Lifecycle Awareness in Jetpack Compose MVI Composable

I'm working on a stateful Jetpack Compose composable that follows the MVI architecture. I'm using collectAsStateWithLifecycle() to observe the view state from a view model, but I'm unsure about the ...
1 vote
0 answers
41 views

Recursive item recipe creation

I was trying to write code that would get as input a recipe consisting of item materials and would create all possible recipes that could be used to create craftable of the recipe. The Recipe is ...
1 vote
1 answer
49 views

Turn List<Either<A, B>> into Either<A, List<B>>

I'm trying to integrate Arrow-kt's Either into an application that needs to parse and validate filter input. This input is a comma separated list of criteria. ...
1 vote
1 answer
173 views

Lock-free implementation of getAndUpdate() using atomic CAS (Compare-And-Swap) operation

We have the following class written in Kotlin Native with the new Memory Manager (which doesn't require to freeze objects): ...
1 vote
0 answers
32 views

Dialog manager for Compose dialogs

I needed something that would help me keep dialogs in my Jetpack Compose desktop application under control and without dozens of *Visible variables etc, so I ...
3 votes
1 answer
161 views

Kotlin: scoped functions with try/catch support

I'm working with Kotlin for some time. Compared to Java it's more concise. Still it has some legacy inherited from Java. For example the try-catch-construct. Though it has been upgraded from a ...
0 votes
0 answers
61 views

Small DSL for SQLite's where clause

I've got an application with a filter that offers the user over 30 different search cirteria that I need to translate into an SQLite query. A small DSL should simplify creating more efficient ...
2 votes
1 answer
335 views

Android: Navigation with Hilt + Jetpack Compose

The project is simple: Login screen and a forgot password screen. You can navigate from Login to ForgotPassword. I feel like I overcomplicated things, but I don't know if (and how) it can be ...
0 votes
1 answer
178 views

Dynamic Priority Heap - Kotlin

...
3 votes
1 answer
66 views

Solve the snake cube puzzle

I wrote a solver for the snake cube puzzle. The solver can be easily adapted to arbitrary snakes. Since the program takes only a few seconds to run, I didn't care to optimize for speed, instead I ...
4 votes
1 answer
93 views

Constructing constrained/validated objects

I'm trying to do some rudimentary DDD in validating my objects to ensure they are of a particular type. I.e. an Email object would always look like "[email protected]" ...
4 votes
0 answers
903 views

Wrap location API in coroutines

In my app I need to query location and scan wifi periodically. To conserve power I need to change the rate dynamically, depending on the distance to the target. Also I want to wait for both ...
2 votes
1 answer
578 views

Getting a value with timeout using Kotlin coroutines

So, here's a task. A background thread may or may not call all of it's listeners some time after sendRequest() was called (in other words ...
1 vote
1 answer
983 views

Am I wrapping synchronous code in ktor/Kotlin coroutine correctly?

I'm playing with ktor right now. If I understand this correctly, code in ktor's handlers need to be as asynchronous as possible. So I was trying to figure out how do you write synchronous (potentially ...
4 votes
1 answer
2k views

Correct flow between Kotlin, Realm and ViewModels using Coroutines

I'm stepping back into Android after being away from it for about a year. Trying to get an out of date app of mine back on its feet, and continuing work on it. The app was written using Java, MVP, ...
3 votes
2 answers
398 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 ...
5 votes
3 answers
587 views

Mapping named parameters to indices for PreparedStatement

I needed something to map named SQL parameters into indices for JDBC queries so I wrote the ParameterMap class that takes an SQL query, searchers for parameters ...
0 votes
0 answers
62 views

Mapping named parameters to indices for PreparedStatement as DSL - follow-up

In the previous question I showed you my first attempt to handle named SQL parameters with JDBC and you were right, it wasn't as intuitive as I thought. The ...
1 vote
0 answers
77 views

Import large Excel files directly from XML streams into an SQLite database

I've got some pretty large Excel files with nearly 1M rows that are almost impossible to open and work with in Excel anymore that I'm migrating into a database. Desipte this these files will stick ...
2 votes
1 answer
75 views

TicTacToe OOP approach in Kotlin

I wrote a terminal-based TicTacToe game in Kotlin to practice both Kotlin and OOP. Any feedback on structure and code would be appreciated. Board.kt ...
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. ...
3 votes
3 answers
149 views

Kotlin call API and store JSON files locally

I'm new to Kotlin and wanted to give this mini project a try. Please let me know if you have any improvements in mind. I'm thinking error handling, structuring the module, is there too much going on ...
9 votes
2 answers
923 views

Swift-function which counts the letters, numbers, spaces, special chars in a given string

Task description: Write a function, which counts the letters, spaces, number and special characters in string. My implementation: ...
3 votes
1 answer
209 views

Jetpack Compose: Length-Units Converter

I have made a length-units converter with Jetpack Compose. Here's the source-code: ...
1 vote
0 answers
57 views

Architecting my Compose UI

I have designed a layout that includes recipe details and three CTAs in the app bar to share, delete, and edit recipes. I need feedback regarding the architecture of my Compose UI. ...
1 vote
1 answer
96 views

Simple Kotlin Bingo Class

This is a simple class in Kotlin that handles three basic Bingo-related functionalities: Specifying the numbers, generating a card, and calling one random element. Additionally, it should support an ...
7 votes
1 answer
132 views

Loading-content-error implementation for a tiny Kotlin library

I have a sealed interface that I use in pretty much every one of my Android projects. It implements the loading-content-error pattern, often called a Resource, <...
0 votes
1 answer
340 views

Assert MockMvc response by using Kotlin DSL

I build web application using Kotlin and Spring Boot, I use MockMvc to write integration test. I'm not satisfied how assertion looks like, here is typical assertion: ...
4 votes
3 answers
288 views

Word-guessing game

The objective of the game is to guess a five-lettered word in five guesses or less. When the user (player) enters a word, the application will inform the user whether their guess was correct or not. ...
4 votes
2 answers
738 views

Given an EAN-8 or an EAN-13 code, tell if that code is valid

I have the requirement to validate product codes which include EAN-8, EAN-13 and UPC-A encoded as EAN-13. I have implemented a use-case to perform this check by comparing the actual check digit with ...
2 votes
1 answer
45 views

Remove inputted keys separated by spaces from map and output the resulting map, including alias recognition

I'm looking to integrate Kotlin idioms (including code style) and maybe better performance. I wonder if there's a better way to do line 17 (the str.split(' ') one). ...
1 vote
0 answers
55 views

Learning Jetpack Compose: TabBar with Paging Screens

I'm piecewise reimplementing an existing iOS app. My initial go at it visually looks like this: I'm looking for any feedback on more idiomatic ways to implement what I've done. There's a couple of ...
0 votes
1 answer
345 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 ...
3 votes
0 answers
143 views

Advent of Code 2021 Day 19

I am taking advantage of the recent layoffs to teach myself Kotlin. I am a career Java programmer, I've touched Kotlin before but not actively, and not for a few years. I wrote it all in one file ...
1 vote
0 answers
186 views

Jetpack Compose: Items-list with Item-Details-view

The app is based upon an exercise from a Udemy-course. The purpose is to become familiar with LazyColumns. I've enhanced the exercise with a Details-view and a navigation between LazyColumn and ...
1 vote
0 answers
34 views

Kotlin JSR 310 validation annotation

So, I am trying to implement an annotation in Kotlin, and it works, but I definitely feel like I could do a lot better. Below is the code and some areas I think could be improved. The purpose of this ...
1 vote
0 answers
290 views

An automated jOOQ-query-builder based on input using JSON in Kotlin

In my current project, I have to build a criteria builder which users can use to find "contacts" (the definition of which is not relevant). For this, I have created the front-end in Elm, ...
4 votes
3 answers
392 views

Removing repeating rows and columns from 2d array

This is a real problem I had to fix recently. Imagine having generic array where you can have duplicate columns and rows. You want to remove those duplicates as long as they are next to each other. <...
2 votes
1 answer
80 views

Splitting a list in Kotlin

I want to split a list (as if splitting a string by a delimiter), ideally in a functional style, and was surprised how hard it seems to be. Or maybe my code is just unnecessarily complicated? ...
2 votes
2 answers
335 views

Temperature Scale Converter in Kotlin

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
2 votes
1 answer
119 views

Function to capture all stdout to String

I wanted to have a simple way to capture all sysout for a block of code. Ended up with this: ...
2 votes
1 answer
243 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 ...
-1 votes
3 answers
198 views

Android - A way to show/hide loader without writting false/true in every viewmodelScope.launch

I have been writting a lot of code that looks like this ...
4 votes
1 answer
775 views

Android + Kotlin advanced color picker (HSV and RGB)

For almost the past year, I have been working on a pixel art editor for Android. My pixel art editor was relying on an external library for its color picker. For 0.2.0, I wanted to change this by ...
2 votes
1 answer
48 views

Observe LiveData to indicate whether or not to display TextViews in MVVM

In the context of MVVM, is this an efficient way to communicate to the view that I should display some TextViews? Any advice on how I can improve it? ViewModel code: ...
2 votes
1 answer
74 views

Processing charge current error messages with HashMap<>

I have certain error states that I am displaying in my Android TextView but only one message is displayed at a time and if all values are set to 0, no message is displayed. So, I check all the values ...
2 votes
2 answers
62 views

Load data from database, change it asynchronously and return the new data

I have written this function to load data from the database, change it asynchronously and return the new data. It appears to work fine, but since I am new to Kotlin, I wanted to ask if this code is ok ...
2 votes
1 answer
54 views

parsing source code to generate documentation of an open source program (StreetComplete, an OpenStreetMap editor) - 1180 lines of Kotlin script

All help welcomed! I posted a big chunk of code here - but feel free to review only a small section. I will use answers to improve this deployed open source software. About the code This code works. ...
3 votes
0 answers
1k views

Jetpack compose login screen + ViewModel

Im working on the login screen for my application. It has fields for users email and password. Also users can click on forgot password button to send an email with new passsword. It can validate these ...
5 votes
3 answers
184 views

Performing complex operation before calling the primary constructor in Kotlin

Semester is a simple enum class. ...

1
2 3 4 5 6