- You can find the article published here: http://www.javiersoto.me/post/106875422394
- For questions, it's also available on Github: https://github.com/JaviSoto/Blog-Posts/blob/master/Functor%20and%20Monad%20in%20Swift/FunctorAndMonad.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package akka.http.scaladsl | |
import java.io.File | |
import akka.http.scaladsl.unmarshalling.Unmarshal | |
import akka.util.ByteString | |
import scala.concurrent.duration._ | |
import akka.actor.ActorSystem |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codetinkerhack | |
import akka.actor.{ ActorRef, Props, Actor, ActorLogging } | |
import akka.pattern.ask | |
import akka.util.Timeout | |
import scala.concurrent.duration._ | |
import akka.actor.Actor.Receive | |
import akka.pattern.pipe | |
import scala.util.Success | |
import scala.util.Failure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val buildFiles = SettingKey[Map[File, Seq[Byte]]]("build-files") | |
buildFiles := getBuildFiles((baseDirectory in ThisBuild).value) | |
def getBuildFiles(base: File) = | |
((base * "*.sbt") +++ ((base / "project") ** ("*.scala" | "*.sbt"))).get.map{ | |
f => f -> collection.mutable.WrappedArray.make[Byte](Hash(f)) | |
}.toMap | |
def changed(base: File, files: Map[File, Seq[Byte]]): Boolean = |
"For comprehension" is a another syntaxe to use map
, flatMap
and withFilter
(or filter) methods.
yield
keyword is used to aggregate values in the resulting structure.
This composition can be used on any type implementing this methods, like List
, Option
, Future
...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number::pad = (digits, signed) -> | |
s = Math.abs(@).toString() | |
s = "0" + s while s.length < digits | |
(if @ < 0 then "-" else (if signed then "+" else "")) + s | |
Date.months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] | |
Date.weekdays = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ] | |
Date.formats = | |
"a": -> Date.weekdays[@getDay()].substring(0, 3) |