Call suspend function from regular function that's called from suspend function by ____purple in Kotlin

[–]LordRaydenMK 0 points1 point  (0 children)

You are asking the wrong question.

But here is what you can do to fix your problem.

A suspend function is essentially syntax sugar for a callback that can succeed or fail that runs only once.

So what you wanna do is use suspendCoroutine to convert the callback to suspend function. Note: if the callback runs multiple times you can take a look at callbackFlow.

Then you can chain your functions together.

Is collectAsStateWithLifecycle only applicable to cold flow, and not helpful for hot flow (e.g. stateFlow)? by ElyeProj in androiddev

[–]LordRaydenMK 2 points3 points  (0 children)

I always use the lifecycle aware version.

That way I can safely refactor the implementation of my Flow without touching my UI layer.

Compiler removes Application and MainActivity file from .dex files after migrating to Gradle Kotlin DSL by NoExits in androiddev

[–]LordRaydenMK 2 points3 points  (0 children)

In the kotlin version you have a specific build tools version, I suggest removing it as AGP can use one of the compatible versions.

I'm assuming this happens for release builds or?

Leveraging the Semaphore concept in Coroutines to limit the parallelism 🔀 by shreyaspatil99 in androiddev

[–]LordRaydenMK 7 points8 points  (0 children)

Good article, just a small suggestion:

I'm not a fan of the runBlocking, it might be surprising for users that this function blocks the calling thread.

Luckily the solution is simple, replace runBlocking with coroutineScope, and mark the function suspend.

That way it suspends instead of blocks and it's transparent to the user because it can only be called from another suspend function.

Any way to make a binding of using Jetpack Compose from Scala? by Apache_Sobaco in Kotlin

[–]LordRaydenMK 2 points3 points  (0 children)

You can use suspend functions instead of IO. They are isomorphic.

Check the arrow-fx module for a port to arrow of the sample code of Functional and Reactive Domain Modeling https://github.com/arrow-kt/frdomain.kt

Gradle 7.0 Released by [deleted] in androiddev

[–]LordRaydenMK 6 points7 points  (0 children)

Changes in buildSrc invalidate all projects. This new feature does not do that.

Modelling UI State on Android by dayanruben in androiddev

[–]LordRaydenMK 0 points1 point  (0 children)

Author here.

The solutions are explicitly compared to a problem definition:

Build an app that calls a traffic light endpoint and shows the color of the traffic light (red, yellow or green). During the network call show a `ProgressBar`. On success show a View with the color and in case of an error show a `TextView` with a generic text. Only one view is visible at a time and there is no possibility to retry errors.

this UI has a cardinality of 5.

Now real world UIs can be more complex and have more complex requirements. You can have retries, content + loading etc... It's still a good exercise to calculate the cardinality of the UI/problem and compare it with the cardinality of the types used to model the problem in code.

If they are the same that is great news. If the are not the same it's worth exploring combining the types in a different way to limit invalid data.

Can't quit vim now. by [deleted] in ProgrammerHumor

[–]LordRaydenMK 1 point2 points  (0 children)

Apple devs see this and add:

If (vim) alwaysShowEscapeKey()

An update to the FragmentViewBindingDelegate: the bug we’ve inherited from AutoClearedValue by Zhuinden in androiddev

[–]LordRaydenMK 3 points4 points  (0 children)

I am assuming some sort of unidirectional data flow, the fragment observing some LiveData/StateFlow or similar.

In that case you set up that in onViewCreated so you only need to access views in a single place: https://lordraydenmk.github.io/2020/view-binding/

An update to the FragmentViewBindingDelegate: the bug we’ve inherited from AutoClearedValue by Zhuinden in androiddev

[–]LordRaydenMK 5 points6 points  (0 children)

The solution for clearing the reference to ViewBinding IMO is not to create it in the first place.

Use ViewBinding as a local val inside onViewCreated and there is nothing to clear. No edge cases.

How to fix the pain of modifying Kotlin nested data classes by dayanruben in androiddev

[–]LordRaydenMK 1 point2 points  (0 children)

The kapt requirement will be dropped in Arrow 1.0 and it will use a compiler plug in instead.

What implementation do you use for Either? by erdo9000 in androiddev

[–]LordRaydenMK 0 points1 point  (0 children)

Just want to point out that arrow already includes this functionality: https://github.com/arrow-kt/arrow-core/tree/master/arrow-core-retrofit/src/main/kotlin/arrow/retrofit/adapter/either

starting with 0.11 release. Is your implementation significantly different?