Posts

Showing posts from May, 2018

cats/cats-effect and webservices function composition

cats/cats-effect and webservices function composition If you use webservices, say in a CLI program, then you are familiar with the following pattern: // typing in the types to show what they are... val entityA : IO [ Option [ A ] ] = getAByName ( "aname" ) val entityB : IO [ Option [ B ] ] = getBByName ( "bname" ) // ... // useIt does not return an Option. def useIt ( a : A , b : B , . . . ) : IO [ D ] = { . . . } // how do you call `useIt`? Here, the input “aname” comes from the user and is not a primary key (PK). The “get” has to search a list and if it finds a result, returns a single object. Or if the name is not found, it returns None . If the request finds more than 1 value, perhaps it returns None or signals an error (your choice). This is a classic problem in scala, that is, the effects returned in the get*ByName functions have efffect wrappers and we need to unwrap/drill-into them to use the data inside....

skip scalajs-bundler, use npm/webpack directly with sbt/scalajs

skip scalajs-bundler, use npm/webpack directly with sbt/scalajs Many people are using scalajs-bundler to specify their javascript dependencies using npm-style (sbt first, npm second) declarations. You don’t need to use scalajs-bundler, which can be confusing to use or perhaps less useful in complex bundling scenarios. If all you need is some simpler webpack config, use scalajs-bundler and ignore the content below. If not, you can still retain the flexibility of running npm after your compile triggers on source code change using the standard approach shown below. First, set up a webpack config. Only the relevant parts are shown: // config file myapp.webpack.config.js const common = { ... whatever you want ... . } // I typically parameterize the scala.js output based on the // build kind but you can also be explicit if you wish const prod = { mode : "production" , // prod by default, webpack 4 entry : path . resolve ( __dirname , ...