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

Fight Complexity with Functional Programming

Fight Complexity with Functional Programming

More about this talk can be found here: https://overfullstack.github.io/posts/fight-complexity-with-fp/

Gopal S Akshintala

August 21, 2019
Tweet

More Decks by Gopal S Akshintala

Other Decks in Programming

Transcript

  1. @GopalAkshintala - Some Manager (Not Mine!) FP is cool ,

    coz it’s complex enough to make devs feel like they are doing something smart!
  2. Let’s Concatenate last names in a team with a delimiter

    lastName1 lastName2 lastName2 @GopalAkshintala Team Building!
  3. • Configure the order of Validations • Cross-Share Common &

    Nested Validations • Fail-Fast or Error-Accumulation • Partial failures Framework Requirements @GopalAkshintala
  4. • Accommodate a century validations • Unit testability • No

    compromise on Performance Framework Meta Requirements @GopalAkshintala
  5. @GopalAkshintala static boolean validate1Simple(Map<Integer, ValidationFailure> badEggFailureBucketMap, int eggIndex, Iterator<Egg> iterator,

    Egg eggToBeValidated) { if (!simpleOperation1(eggToBeValidated)) { iterator.remove(); badEggFailureBucketMap.put(eggIndex, NO_EGG_TO_VALIDATE_1); return false; } return true; } static final Validator<ImmutableEgg, ValidationFailure> validate1Simple = validatedEgg "-> validatedEgg .filter(Operations"::simpleOperation1) .getOrElse(() "-> Either.left(NO_EGG_TO_VALIDATE_1)); validate1Simple
  6. @GopalAkshintala private static boolean validate2Throwable(Map<Integer, ValidationFailure> badEggFailureBucketMap, int eggIndex, Iterator<Egg>

    iterator, Egg eggToBeValidated) { try { if (!throwableOperation2(eggToBeValidated)) { iterator.remove(); badEggFailureBucketMap.put(eggIndex, TOO_LATE_TO_HATCH_2); return false; } } catch (Exception e) { iterator.remove(); badEggFailureBucketMap.put(eggIndex, ValidationFailure.withErrorMessage(e.getMessage())); return false; } return true; } static final ThrowableValidator<ImmutableEgg, ValidationFailure> validate2Throwable = validatedEgg "-> validatedEgg .filterOrElse(Operations"::throwableOperation2, ignore "-> TOO_LATE_TO_HATCH_2); validate2Throwable
  7. Configure the order of Validations Cross-Share Common & Nested Validations

    Fail-Fast or Error-Accumulation Partial failures Framework How-to-dos @GopalAkshintala
  8. Configure the order of Validations Cross-Share Common & Nested Validations

    Fail-Fast or Error-Accumulation Partial failures Framework How-to-dos @GopalAkshintala
  9. Configure the order of Validations Cross-Share Common & Nested Validations

    Fail-Fast or Error-Accumulation Partial failures Framework How-to-dos @GopalAkshintala
  10. Transformation map flatMap filter Aggregation reduce collect groupBy zip,unzip foldLeft,foldRight

    scanLeft,scanRight @GopalAkshintala Dozen FP Operations for Daily Programming
  11. Configure the order of Validations Cross-Share Common & Nested Validations

    Fail-Fast or Error-Accumulation Partial failures Framework How-to-dos @GopalAkshintala