Tuesday 21 May 2013

Map’s Friends: Reduce and FoldLeft (and a First Toe-Hold)

WARNING: KOAN SPOILER ALERT

This isn’t the original version of this post. There was a first draft which banged on about the impenetrable math-lingo which Scala is steeped in. But that was before I researched and wrote Higher Order Functions <gulp/>. That helped a lot. It felt as if it gave me a toe-hold on the Functional cliff-face. The one hiding just behind the basic syntax. The one which still looms above me.

Now I’m of a much more positive frame of mind. Lets start with reduce.

Now I’m beginning to get over my fear of ‘_’, this was something I could understand.  I wasn’t sure from the Koan code alone initially what this function did, but after a bit of guess-work I got it to work. Again I think I need to come up with a memorable image to associate with this to make it really persist "up there”, but in the meantime I can appreciate how powerful this could be.  I’ll post on my background reading on reduce and foldLeft (and map) later.

Moving on to foldLeft:

This time I could guess pretty easily.  Nice.  Still no mental image springs to mind, but I’m patient.

But what’s this about “currying”?  Patience.  We’ll get there.

2 comments:

  1. Definitely patience about the currying. About the only reason I can think you want this comment is so that you can review later. Otherwise the comment seems to distract as much as it enlightens. On second thought, the currying syntax is different from the direct application syntax so either seems like a bit leap.

    ReplyDelete
  2. Thanks @Semeru. I'm fighting the many urges I'm getting to jump ahead (post on that coming soon).

    ReplyDelete