juan_gandhi: (VP)
2013-10-14 01:31 pm
Entry tags:

the thing I do too many times, but can't find the right word for


val listMaybe: Result[List[X]] = ...
val extractionResults: Result[List[Result[Y]]] = listMaybe map process
extractionResults map traverse flatten


I have a result of type Result[List[Result[Y]]]; now I traverse the internal list (if it exists), obtaining Result[Result[List[Y]]], then I have to flatten it to get Result[List[Y]].

Either I'm doing something non-kosher, or I need a word for this "map traverse flatten" thingie.
juan_gandhi: (Default)
2011-05-10 11:17 pm

Now again


  1. a not totally trivial example implemented using JPA and Scala

  2. an event sourced implementation using explicit state changes

  3. a straightforward translation of the mutable event sourced implementation into an immutable implementation

  4. encoding domain knowledge into the type system to make the domain easier to understand and reduce the number of runtime error checks

  5. Towards an immutable domain model – monads (part 5) the stuff above translated into monads (where it should be)
juan_gandhi: (Default)
2011-01-24 10:32 pm

the simple thing I missed in Scala

  def bytes(is: InputStream) : Iterator[Byte] = new Iterator[Byte] {
    def hasNext = is.available > 0
    def next = is.read.toByte

  def isText(b: Byte) = b == 0x0a || b == 0x0d || b >= 32 && b < 0xff

  def chars(is: InputStream) = bytes(is) filter isText map (_.toChar)



So that I can use it like this:
  def main(args: Array[String]) {
    val is = new FileInputStream(args(0))
    for (c <- chars(is)) print(c)
  }


(that's monadic, kind of)