Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Fight Complexity with Functional Programming in Kotlin

Fight Complexity with Functional Programming in Kotlin

A Metric-driven approach to reduce Cognitive Complexity in a code base, using Functional Programming, demoed hands-on, by solving a complex real-world ubiquitous design challenge - REST API Bulk Request Validation, with an extensible Framework that separates what-to-do (Validations) from how-to-do (Validation Orchestration). Let’s do a case study of a successful implementation done by our team in the world’s largest SaaS org, Salesforce, through our in-house baked FOSS library Vader.

Gopal S Akshintala

April 16, 2020
Tweet

More Decks by Gopal S Akshintala

Other Decks in Programming

Transcript

  1. FP is cool , coz it’s complex enough to make

    devs feel like they are doing something smart! @GopalAkshintala - Some Manager (Not Mine!)
  2. Let’s Concatenate last names in a team with a delimiter

    lastName1 lastName2 lastName2 @GopalAkshintala Team Building!
  3. @GopalAkshintala val validate1Simple: Validator<Egg, ValidationFailure> = { if (simpleRule(it)) true.right()

    else NO_EGG_TO_VALIDATE_1.left() } validate1Simple fun validate1( badEggFailureBucketMap: MutableMap<Int, ValidationFailure>, eggIndex: Int, iterator: MutableIterator<Egg?>, eggToBeValidated: Egg? ): Boolean { if (!simpleRule(eggToBeValidated)) { iterator.remove() badEggFailureBucketMap[eggIndex] = ValidationFailures.NO_EGG_TO_VALIDATE_1 return false } return true }
  4. Transformation map flatMap filter take… Aggregation reduce groupBy zip,unzip fold,foldRight

    scan,runningReduce @GopalAkshintala Dozen FP Operations for Daily Programming