jeffsheets,
@jeffsheets@hachyderm.io avatar

Kotlin's mapNotNull is beautiful magic

jeffsheets,
@jeffsheets@hachyderm.io avatar

New fave #kotlin thing is elvis operator with a tiny block of code:

val message = errorMessage ?: run {  
 logger.error { "unknown error" }  
 "Error, please try again"  
}  
jeffsheets,
@jeffsheets@hachyderm.io avatar

kotlin async code is so friendly -- this is super contrived here but the point is still valid I think:

return accounts.mapNotNull { account ->  
 async { fetchFromOtherSystem(account) }  
}.awaitAll()  

#kotlin

jeffsheets,
@jeffsheets@hachyderm.io avatar

constants are weird in Kotlin. every language has one or two things that should be simple but are weird. I still love kotlin but still struggle with constants, and how copy/pasting files will drop them in IntelliJ every time because they are top-level and semi-classless

https://stackoverflow.com/questions/44038721/constants-in-kotlin-whats-a-recommended-way-to-create-them

#kotlin

emurphy,
@emurphy@fosstodon.org avatar

@jeffsheets it took me a few months to learn Kotlin. Longer than I expected. But I would have a hard time going back to Java now.

emurphy,
@emurphy@fosstodon.org avatar

@jeffsheets I am using Kotlin for Spring Reactive BTW

jeffsheets,
@jeffsheets@hachyderm.io avatar

@emurphy same here! Kotlin is great. And I'm using with Spring Reactive too

jeffsheets,
@jeffsheets@hachyderm.io avatar

Love how Kotlin builds in helpers to all sorts of random things that Java never got around to doing. The padStart function came in super handy when saving data to a mainframe today and needing to pad zero's in front of the last four of an SSN:

request.ssnLastFour?.padStart(9, '0')  

#kotlin

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • modclub
  • Youngstown
  • khanakhh
  • Durango
  • slotface
  • mdbf
  • cubers
  • GTA5RPClips
  • kavyap
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • megavids
  • osvaldo12
  • tester
  • tacticalgear
  • ethstaker
  • Leos
  • thenastyranch
  • everett
  • normalnudes
  • anitta
  • provamag3
  • cisconetworking
  • JUstTest
  • lostlight
  • All magazines