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
/* Start by creating a reader for some fake yet conceivable type for executing SQL queries. */ | |
val dbReader: Reader[Properties, JdbcExecutor] = | |
for { | |
driver <- read[String]("db.driver") | |
uri <- read[String]("db.uri") | |
user <- read[String]("db.username") | |
password <- read[String]("db.password") | |
name <- read[String]("db.pool.name") | |
minCons <- read[Int]("db.pool.minConnections") |
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 getJDBCConnection: Reader[JDBCConf, Connection] = ??? | |
val getStatement: Reader[Connection, PreparedStatement] = ??? | |
val executeQuery: Reader[PreparedStatement, ResultSet] = ??? | |
val queryExecutor: Reader[JDBCConf, ResultSet] = getJDBCConnection.andThen(getStatement).andThen(executeQuery) |
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
Monad | effect | sequences the effect as | M[A] | bind: M[A] => (f: A => M[B]) => M[B] | |
Identity | nothing | continue | Id[A] | f(a) | |
Option | zero or one value (anonymous exception) | halt if None | Option[A] | if Some(a) f(a) | |
Either | exception with error type or one value | halt if Left | Either[L, A] | if Right(a) f(a) | |
List | any # of values (non-determinism) | halt if empty | List[A] | join(each f(a)) | |
Reader | an environment; dependency-injection | function composition | R => A | (r: R) => f(a(r)) | |
Writer | logging | append log value W | Writer[W, A](log: W, value: A) | k = f(a.value); Writer(a.log |+| k.log, k.value) | |
State | state | new state from old | State[S, A](s: S => (S, A)) | | |
Responder | continuation-passing |
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
/// REPL Testing | |
// | |
// ----------------------------------------- | |
$ scala | |
Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_20). | |
Type in expressions for evaluation. Or try :help. | |
scala> case class Reader[C, A](g: C => A) { | |
| def apply(c: C) = g(c) |
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
/* | |
Based on the first part of the talk "Dead-Simple Dependency Injection in Scala" by @runarorama at NEScala 2012 | |
http://marakana.com/s/dependency_injection_in_scala,1108/index.html | |
*/ | |
class Connection { | |
def prepareStatement(query: String) = new Statement() | |
} | |
class Statement { |
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
(defun postscript-process () | |
(get-buffer-process (get-buffer "*postscript*"))) | |
(defun run-postscript () | |
(interactive) | |
(require 'comint) | |
(switch-to-buffer (make-comint "postscript" "gs"))) | |
(push '("postscript" . utf-8) process-coding-system-alist) |
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
%!PS | |
%%DocumentMedia: a4 595 842 80 () () | |
/pageHeight 842 def | |
/pageWidth 595 def | |
<< /PageSize [pageWidth pageHeight] >> setpagedevice | |
/mm { 2.834645669 mul } def |
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
newpath | |
300.0 400.0 moveto | |
gsave | |
currentpoint translate | |
-241.66666666666669 0.0 rmoveto | |
108.33333333333334 0.0 rmoveto | |
gsave | |
currentpoint translate | |
-108.33333333333334 0.0 rmoveto | |
25.0 0.0 rmoveto |
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
;; Get package installation ready | |
(require 'package) | |
(setq package-enable-at-startup nil) | |
(add-to-list 'package-archives | |
'("melpa" . "https://melpa.org/packages/")) | |
(package-initialize) | |
;; Bootstrap `use-package' | |
(unless (package-installed-p 'use-package) | |
(package-refresh-contents) |
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
;; 1. place this in ~/.emacs.d/private/intero/packages.el | |
;; 2. add intero, syntax-checking and auto-completion to your | |
;; ~/.spacemacs layer configuration & remove the haskell layer | |
;; if you were using that before | |
;; 3. make sure you have stack installed http://haskellstack.org | |
;; 4. fire up emacs & open up a stack project's source files |