Sunday, May 13, 2018

Thoughts On Working With Nested Monad Within The Future Monad In Scala

This post is about nested contexts, specifically with Future, or more accurately, nested monad within the Future monad. eg: Future[Either[E, A]], Future[Option[A]] etc. And how such nested context could easily lead to hard to read and hence hard to maintain codebase.

These sort of context nesting and its impact is not limited to Future, but I would be using Future as the reference in this post, strictly because they seem to be the form that appears the most in a particular Scala codebase I work on at my day job.

Also in this post, I would use Monad and Context interchangeable to mean the same thing. I would also mention terms like Monads, Monad Stack, Monad Transformers, or For Comprehension without providing any explanation of these terms. This is because the thrust of this post is not to expound on these concepts but to share some recent thoughts I have been having regarding nested context within Future.

A reader not familiar with these concepts should still be able to follow along though.

Thursday, April 19, 2018

ip-num 1.0.1 is Released

ip-num, version 1.0.1 is now available. It is mainly a bug fix release.

The release contains the following changes/fixes:

  • Fixed the throwing of the invalid integer: NaN when invalid IPv4 and IPv6 strings are passed to Validator.isValidIPv4String and Validator.isValidIPv6String validators. Fixed by saiyeek Issue #5
  • Fixed Validator.isValidIPv4CidrNotation improper validation of IPv4 CIDR Issue #6
  • Renamed Subnet to SubnetMask Issue #1
You can download the source here. Or just run:

npm install ip-num //or npm install ip-num@1.0.1

to add ip-num as a dependency to your next project.

Wednesday, March 14, 2018

An easier way to interpret code blocks and curly braces in Scala

I recently realized a nifty way for reading a particular piece of Scala syntax that has always confused me.

Basically how to interpret code that makes use of curly braces when calling functions with multiple parameter lists or code that makes use of {} in place of () when acceptable.

Basically, code that looks like this:

foo() {
  val a = "Hello"
  val b = "world"
  s"$a $b"


foo() { (x:Int) =>
  val y = x * 2
  println(s"output is: $y")

Or a snippet of code defining a controller method using the play framework:

Action.async(action.parser) { request =>"Calling action")

Or some slightly modified code from a code base at work:

extractActiveMembershipFromRequest(membershipKey) { requesterId =>
...some code here...

Or another slightly modified code from work:

secure.hasRequiredRole(user, role) {