Scala Maybe

I wrote a Maybe that I can use in Scala. Scala Maybe … because I wanted a lazy variant of Option[+T] for those cases where Gradle needs me to produce something, but, I know darn well that the rest of the project model hasn’t been setup. package peterlavalle /** * like Option[+A] but lazy */ trait Maybe[+T] { def bind[V](map: T => V): Maybe[V] def some: Option[T] } object Maybe { case object Nope extends Maybe[Nothing] { override def bind[V](map: Nothing => V): Maybe[V] = Nope override val some: Option[Nothing] = None } private class Just[T](read: => T) extends Maybe[T] { lazy val some: Option[T] = Some(read) override def bind[V](map: T => V): Maybe[V] = Maybe { map { some.

S-State

Source mirror; https://github.com/g-pechorin/sstate.scala Won’t actually build, use the full repository here Releases (tags) https://github.com/g-pechorin/sstate.scala/tags "com.peterlavalle" %% "sstate" % ??? 'com.peterlavalle:sstate_2.12:???' SState SState is a cute little pure-functional FSM class in Scala that I wrote after seeing JEasyStates. The only real advantage of mine is that it can (probably) be dropped into a Scala.JS project without any magic. There’s a unit test at the foot of this doc showing how I test 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.