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.

0
votes
0answers
5 views

Companion object and static functions in kotlin [on hold]

Is it good idea to define static functions as compananion object in Kotlin under util nd use this way... ...
0
votes
0answers
11 views

Adapter for Spinner

I need to my spinner supported endless scrolling. As rule the user will have only 1 - 5 items but in very rare cases some users can have 100+ items that will be loaded from server by pages (15 per ...
4
votes
1answer
24 views

Finding the number of pairs in an integer Array

This function returns the number of pairs of the same elements in the array It takes, array length and the array as the parameter n: Length of array ar: Array of integers for example ...
0
votes
0answers
13 views

CLI to make HTTP Head requests and check for response code

I needed to create a simple CLI utility to check if a specific endpoint is available and (optionally) responds with some expected HTTP code to help troubleshoot users environments (proxy, network ...
0
votes
0answers
18 views

Android LiveData Shared between activities by Application Session

I'm developing an app that use socket to receive messages from a chat. I'm using an MVP approach and I store the data in a Singleton class named DataBridge like ...
5
votes
0answers
141 views

Converting between cooking measurements

I've made an Android app that converts between cooking measurements, taking into account the type of product you use (that way it can convert between mass and volume by using the density). What are ...
2
votes
1answer
35 views

Determine if a String can be parsed to LocalDateTime or Int

I have the following kotlin function that takes in a string "value", then attempts to parse "value" as both a LocalDateTime and an Int. It returns a Pair of the parsed value of "value" and an enum ...
1
vote
0answers
29 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 ...
4
votes
2answers
795 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 ...
1
vote
1answer
118 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
25 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
76 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
47 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
63 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
13 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
43 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
31 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
92 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
30 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
194 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
400 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
28 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
142 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
209 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
43 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
73 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
581 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
44 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
133 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
65 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
57 views
2
votes
0answers
369 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
36 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
168 views

JDBC wrapper in a functional manner

I implemented a simple Java JDBC wrapper in Kotlin with Arrow functional library. ...
2
votes
1answer
45 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
190 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
163 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
263 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
282 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
768 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
89 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
53 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
244 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
97 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
45 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 ...