Learner Learning Software Engineering
Posts with the tag Kotlin:

Android Sample Chat Application using Azure Communication Services and ChatKit

This post demonstrates the Android chat application leveraging Azure Communication Services and ChatKit.

Kotlin map, foldRight & nested functions to implement redux middleware

Kotlin supports Higher order functions. In this blog, I will create a higher order function that will use map & fold right for execution. Before diving into higher order functions, let’s go through map & fold right. map is collective transform operation. var numbers = mutableListOf(1, 2, 3) numbers = numbers.map { it*2 }.toMutableList() // elements in numbers: 2,4,6 foldRight accept initial state, apply initial state to all elements and return final state. var numbers = mutableListOf(1, 2, 3) var result = numbers.foldRight(100, {a,b -> test(a,b)}) private fun test(a: Int, b: Any): Int { return a + b as Int } /* First execution: initial 100 a = 3 b = 100 Second Execution a = 2 b = 103 Third Execution a = 1 b = 105 final: result = 106 */ Let’s create a higher order function Middleware that takes an instance StringApp, has inner function next: Type and return Type.

Dagger, Injecting custom objects (Interface implementation)

It is very connivent to use any DI framework when all the objects required are available in application. For example, I have two classes Logger, Service and class Middleware is dependent on these classes. class Logger() class Service() //this class requires Logger & Service object class Middleware(private val logger:Logger. private val service:Service) // middleware object val middleware = Middleware(Logger(),Service()) Dagger can build objects of Logger and Service classes by indicating @Inject annotation to all three classes internal class Logger @Inject constructor() internal class Service @Inject constructor() //this class requires Logger & Service object internal class Middleware @Inject constructor(private val logger:Logger.

Android/Java Dependency Injection Frameworks (Android Library & App Development)

Below are widely used Dependency Injection frameworks mostly by android & Java application projects. For Android application development, the suggested Framework by Google are Dagger and Hilt. These frameworks help to avoid writing boilerplate code. Guice Guice (pronounced ‘juice’) is a lightweight dependency injection framework for Java 6 and above, brought to you by Google. (github.com) With 10K stars this framework is mostly used by Java developers where Java is used for backend & Application development. For Android, this framework is not suggested as this framework use reflections to scan annotations from code. This requires significant CPU cycles and RAM thus slowdowns application launch.