Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [kotlin]

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

1
vote
0answers
10 views

Temporarily block API calls when server sends a 503 response

I have a scenario in which I call many APIs throughout my application lifecycle. In case the server sends me a 503 response code, it will also send a lockdown object which has a timestamp associated ...
5
votes
2answers
762 views

Compiling and throwing simple dynamic exceptions at runtime for JVM

I've been using my Dynamic Exception with C# for quite some time already and it saved me a lot of time. This means, I don't have to create a new exception ...
-5
votes
0answers
17 views

my kotlin code is to display an onboarding screen when app is launched [on hold]

but instead it keeps stopping even before it starts... this is the code(this is the fragment adapter class) ...
1
vote
1answer
37 views

RSA wrapper written in Kotlin

I've written up a small wrapper for RSA and AES encryption in Kotlin, and I want to make sure I'm not making any glaring mistakes before use it. This is going on a small project with basically no ...
0
votes
0answers
22 views

CPU Barycentric rendering in JavaFX/Kotlin

I am writing a software renderer for the Kotlin port of Dear ImGui. In order to be feature complete, I needed to add barycentric coloring to some triangles for things such as color pickers. I have ...
3
votes
2answers
74 views

Constructing a cumulative distribution function from a histogram

During some running process, a histogram of values shall be build up. When done, the CDF shall be derived from it and used to get the quantiles for some values. My current implementation looks as ...
2
votes
0answers
43 views

Listing YouTube videos using API with RxJava

I am new to RxJava and have the following code which I use to search YouTube videos via the API and ultimately display them in a list. ...
0
votes
0answers
40 views

Destroy Singleton patter in kotlin

I am practicing Singleton pattern in kotlin. It is a quiz app which has question tile with four options and one correctIndex. McqOldActivity.classs ...
0
votes
0answers
12 views

Mapping one object to a data object for the UI

I'm mapping our Lead object (which is very messy) to a data object for the UI. It takes a couple seconds to map 1000 objects, how can I improve the performance? <...
2
votes
0answers
33 views

Quiz for random boolean expressions

Inspired by the various quiz programs on this site, as well as Simon Tatham's puzzle collection, I thought I'd write a quiz that constructs its questions automatically and randomly. A typical session ...
-3
votes
1answer
27 views

Change Kotlin optional-like style [closed]

I have next method in client fun authUser(loginRequest: LoginRequest): String? I need to implement next logic: check if user already exists - nothing to do, if ...
2
votes
1answer
72 views

Sorting algorithms in Kotlin - Bubble, Insertion, Selection, Merge and Quick sort

Introduction I decided to try Kotlin because of its forgiving nature to long-time Java users. I implemented a few introductory sorting algorithms and would like to have them reviewed, not just to ...
2
votes
0answers
28 views

Convert flat object hierarchy to json

I do work for a project currently, where the data is send to the server as application/x-www-form-urlencoded (which is bad, and it should be JSON, but unfortunately I am not able to change this one). ...
1
vote
0answers
114 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 ...
3
votes
1answer
294 views

Mastermind game in Kotlin

I am trying to create an evaluator in Kotlin for the Mastermind game which compares two strings and tells how many letters and letters on the right position they share. I was hoping to get some ...
0
votes
0answers
26 views

Running a JavaFX 11 interface update at regular intervals (in Kotlin)

I want to update a field on a JavaFX 11 UI in response to a thread which retries a process every second and updates statusString with the result. Since the ...
2
votes
0answers
115 views

Timer application in MVP

I create simple Android timer application and I try to use MVP design pattern. I read some tutorials and after that I started writing code. My code is working correctly and as intended. There is ...
1
vote
0answers
147 views

Kotlin DAO with Exposed: How to reduce redundancy in classes?

I'm writing a Kotlin app that uses Exposed (https://github.com/JetBrains/Exposed) as a SQL wrapper to write and read objects from databases. The problem I'm facing is that I end up with 3 classes ...
0
votes
1answer
42 views

Simple Registration Form. I would like to get rid of code duplications

I don't like my current code, because of duplications. What's the best way to leverage Kotlin to make it more concise. I have simple registration form ...
1
vote
0answers
69 views

Lexer for my “Obganism” language

After having rewritten this lexer for the Nth time, I finally feel confident enough to show it publicly. I'm looking for advices to improve my code. The lexer you are going to see is the first step ...
1
vote
1answer
40 views

Proper naming for objects which have a position and bounds on a plane

I have an interface which is for an object which has bounds in a 2D plane. ...
1
vote
0answers
354 views

LiveData, MVVM and Repository Pattern

Is this a good approach or I've just found a nasty workaround? I'm using MediatorLiveData class because seems useful to update the source of a ...
3
votes
1answer
42 views

Ungrouping of values into multiple lists

Given is a list with (possibly) non-unique elements. My goal is to split this list into multiple lists, in sum containing the same elements, but separated in a way that no sublist contains each ...
0
votes
1answer
105 views

Kotlin reflection to generate one class from class similar with similar properties

This code is intended to generate a class (domain) from a class with class with similar/identical properties (api). Motivation is to speed development time when using clean architecture. ...
1
vote
0answers
54 views

Extending kotlinx.html dsl to create functions that include bootstrap classes

I'm looking to create a library that extends kotlinx.html and will include functions that have default css classes. The goal is to be able to use a function row{} ...
1
vote
0answers
47 views
2
votes
0answers
333 views

Endless scroll in kotlin (android)

This is the code of my function to endless scrolling. It's a good practice to bind new disposable in onscroll listener? What do you think about my code? ...
0
votes
0answers
32 views

Thread safe tile grid abstraction and implementation

I'm working on a tile engine and I'm trying to write a nice abstraction for writing Tiles and TileImages (which are just a group ...
2
votes
2answers
50 views

Kotlin program to summarize git commits by regex match

I am trying to learn Kotlin. I am coming from some background in Java. As a learning exercise, I wrote this simple program to summarize occurrences of a string by author email in a list of git ...
0
votes
1answer
132 views

JDBC wrapper in a functional manner

I implemented a simple Java JDBC wrapper in Kotlin with Arrow functional library. ...
2
votes
1answer
43 views

Parsing CAN frames from a ByteArray

Here's my method used for parsing a ByteArray into multiple frames of CAN interface. It works now correctly but it's somewhat ugly in my opinion. It's written in ...
3
votes
2answers
179 views

Find the sum of all digits that match the following digit in a circular list

The challenge The captcha requires you to review a sequence of digits (your puzzle input) and find the sum of all digits that match the next digit in the list. The list is circular, so the digit ...
5
votes
1answer
161 views

Compute PI in Kotlin on a T-shirt

I have written code in Kotlin with the objective of computing Pi in few enough lines so that it looks good on a t-shirt. Can be cut and paste into http://try.kotlinlang.org under "My Programs" and ...
3
votes
2answers
222 views

Kotlin extension functions with null checks

Kotlin defines extension functions like also but they are not null checked. That's fine because you might not need the check. In case you do though, do you see any ...
1
vote
0answers
35 views

Implementation of an ObjectPool

we are trying to implement an object pool. The objects contained are reusable but not thread safe, and creation costs a lot so we went with this idea. We expect that the user of this object will need ...
3
votes
0answers
260 views

Reverse string in Kotlin

In the question of how to reverse a string in Java, a comment mentioned that combining Unicode code points need to be taken into account. The below code works as intended for all test cases I tried. ...
1
vote
0answers
628 views

Parsing a JSON array from a JSON object

So its my first time using Kotlin, and for now I am converting old Java code to Kotlin. I took a simple function to parse a JSONArray from a ...
4
votes
0answers
47 views

Time travelling through state history with persistent consequences

I am working on a game written in Kotlin that has a state management system similar to Redux. The state of the game is kept in a single place and is represented as immutable data classes (no logic). ...
1
vote
1answer
81 views

Kotlin API - endpoint for users

I am writing API in Kotlin - this is my first code in this language. I implemented a very primitive 'player' endpoint. I was wondering if I am doing everything ok (please don't mind the static ...
1
vote
0answers
49 views

Pushing a value to a Processor on a separate thread

I am attempting to use Room along with a full-text search (FTS) table. The issue is that Room doesn't recognize or support FTS tables. Though there is a work around for this; you just create the FTS ...
0
votes
1answer
1k views

Kotlin text validation

I'm new to Kotlin, not so new to Java and Android development. But willing and trying to ...
6
votes
1answer
214 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 ...
3
votes
0answers
88 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 ...
1
vote
0answers
39 views

Modeling domain layer for basic workflow system

As so far I've been mostly developing existing products and doing maintenance/engineering I feel in need to model something from time to time for fun and for self educational purposes. Attached code ...
0
votes
1answer
41 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 ...
1
vote
0answers
69 views

Knuth Morris Pratt substring search algorithm Implementation in Kotlin

Below you can find a Kotlin based implementation of the Knuth Morris Pratt substring search algorithm. Here is the corresponding Wikipedia article. ...
0
votes
1answer
1k views

Simple function that execute an instruction every X time until Y condition is accomplished

What do you think about this implementation? ...
0
votes
2answers
374 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
0answers
47 views
1
vote
1answer
41 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 ...