Scala Maybe

I wrote a Maybe that I can use in Scala. Scala Maybe … because I wanted a lazy variant of Option[+T]. I had a use case in mind at the time, but, since then; I’ve taken another approach. package peterlavalle /** * like Option[+A] but lazy */ trait Maybe[+T] { /** * Apply some operation to the value, and, return a new monad **/ def bind[V](operation: T => V): Maybe[V] /** * if we're empty; produce the other one */ def otherwise[E >: T](them: Maybe[E]): Maybe[E] /** * produce/convert this to a strict Option[T] in preparation for reading or matching it.

Scala Extractors

Scala’s extractors and unapply() represent a concept that I haven’t grok’ed until now. Most demonstrations seem to be too long or use the same types everywhere. Here are my thoughts on the concept; val a: C = ??? val i: I = ??? i match { case a(f: O) => ??? } This will try to call the below method class C { def unapply(i: I): Option[O] = ??? } There’s some more flexibility;

(Scala) Delay Run

I wrote a threading primitive and I’m very pleased with it. I plan to wrap all of my “save file” things in this, from now on. Delay Run This class acts as a sort of “once inactive for X do Y” pattern. In my design, I’m wrapping my save actions in it and triggering schedule() after practically every edit. The class is passed a delay: Long value to specify how long to actually wait - I’m using 1.