User Tools

Site Tools


Dave Orme muses about agile and functional programming.

My current work emphasizes SOA applications using Scala, Kubernetes, and AWS with a React-based SPA front-end. I'm also interested in progressive web applications and developer tools.


Scala, Clojure, and FP


The Cloud

Data-First Development

Older work

Coconut Palm Software home

Donate Bitcoin:



Kubernetes, Docker, Streaming Data, Spark, Scala, Clojure, OSGi, Karaf, GCP, AWS, SQL


Everything I say here is my own opinion and not necessarily that of my employer.


Databinding Chaining ObservableValues together

Sometimes the standard data binding primitives are perfect: data gets converted, validated, and reported nicely. But sometimes one's validation requirements are more than fit nicely into a standard IValidator. And sometimes the data bindingp pipeline that Binding implements for you isn't quite as flexible as one might want.

What I realized after reading quite a bit about monads is that if we treat an IObservableValue as immutable for a given moment in time (e.g.: it only gets changed by an external actor to the system, like the user or a clock or…) then we can chain IObservable values together using a function that maps from one IObservableValue to another in much the same way one would use the map function to transform one functional collection to another. Implementing this idea lets us write code like this:

IObservableValue textFieldTarget = new WritableValue("", String.class);  // Bound to a UI field somewhere
IObservableValue model = new WritableValue(new Integer(1), Integer.class);

ValuePindingPipeline pipeline = new ValueBindingPipeline(bindingContext)
      .map(new IntToSringConversion())

      .map(new IsValidIntegerValidation())
      .map(new ConvertToInteger())
      .map(new RangeCheckValidation())
      .map(new LessThanValidation(someOtherObservable))

As you can see, the resulting code is nice and explicit about what happens everywhere in the pipeline. This is really similar to some ideas that Matt Hall had , just expressed in a more monadic form.



blog/databinding_chaining_observablevalues_together.txt · Last modified: 2014/10/20 15:44 by djo