Showing posts with label scalaz. Show all posts
Showing posts with label scalaz. Show all posts

Saturday, May 17, 2014

Topic from scalaz-stream

I've been playing around with scalaz-stream topics, and didn't understand how they worked. My first attempt was this:



(And note that this was supposed to be just a quick example; you certainly would end up with different threads publishing and subscribing to a topic.)

That had a few problems:

• Line 7-8: the type of out1 is Process[Task, String \/ Int]. Those are useful, but they're only part of the way towards what I needed. What I really wanted was to go from a process to a task to running the task.

• Line 11-13: again, I'm only part of the way there. Both of these produce Task[Unit], and they needed to be run.

So I asked for help on the scalaz mailing list, and Pavel Chlupáček pointed me in the right direction.
The working version is:



• Lines 6-8 produce a Task[IndexedSeq[String \/ Int]], one step further than in the first version (where the steps are process >> task >> run the task).

• Lines 10-12 actually run the task - and anything published before the attemptRun won't be seen by the subscriber.

• Line 19 stalls, waiting for the attemptRun to hook up the subscriber. (As the note says, I think this is only something you'd do for a demo).

• Lines 21-22 actually run the tasks they create

Saturday, January 4, 2014

Using ruby to explore scalaz

I've been poking around scalaz, and sometimes it's nice to just get a quick overview of the code using some simple ruby. I could write some code using asm to look at the bytecode, but it's usually faster for me to just use ruby on the source. I'm not looking for 100%-complete tested code here, it's more like a very fancy grep.

For example, I was curious about all the places that define functions starting with lift:



And then to read the output, I use a google spreadsheet:



Run with:

find * -name *.scala -type f -print0 | xargs -0 ruby lift.rb | pbcopy

pbcopy is the mac utility that copies stdout to the clipboard, so it's fast to run this from the command line, switch to the spreadsheet, and hit paste.

Saturday, August 10, 2013

v50 of AndroidProguardScala released

Just released v50 of the AndroidProguardScala Eclipse plugin. Installation instructions are here, and if you're a current user you can pick it up by asking Eclipse to check for updates.

Changes:

  • Update to latest version of dependencies (Scala 2.10.2, Scalaz 7.0.2)
  • Better checking for Proguard errors

Thursday, August 1, 2013

Glassware in Scala and Scalaz

I've been working on a Scala port of one of the Glassware samples. You'll find the code here on Github.

It has examples of a few really useful Scalaz features.  In particular, it has a bunch of examples of using EitherT in for-comprehensions.

Tuesday, July 24, 2012

scalaz for the Eclipse Scala IDE plugin

There's a brand new build of scalaz 6.0.4 for M5 that seems to work well with the Eclipse plugin.  If you were having issues before with scalaz + Eclipse, give this one a shot:

    <dependency>
      <groupId>org.scalaz</groupId>
      <artifactId>scalaz-core_2.10.0-M5</artifactId>
      <version>6.0.4</version>
    <dependency>