Skip to content

Instantly share code, notes, and snippets.

@d6y
d6y / TopicExplore.scala
Created February 28, 2017 12:31
Two channels
import scalaz.stream.{Exchange, Process, Sink}
import scalaz.stream.async.topic
import scalaz.concurrent.Task
import scalaz.stream.async.mutable.Topic
object TopicExplore {
case class Message(value: String)
@d6y
d6y / TopicExplore.scala
Last active February 28, 2017 12:02
filtering
package foo
import scalaz.stream.{Exchange, Process, Sink}
import scalaz.stream.async.topic
import scalaz.concurrent.Task
import scalaz.stream.async.mutable.Topic
// Useful:
// - https://gist.github.com/djspiewak/d93a9c4983f63721c41c
@d6y
d6y / mapto.sh
Last active March 15, 2017 11:45
Slick 3 to 3.2 :-)
find . -name \*.scala -exec sed -E -i.bak 's| <> \((.*).tupled, .*\)|.mapTo[\1]|' {} +
@d6y
d6y / example.scala
Created February 11, 2017 23:17
Enum example
import slick.driver.H2Driver.api._
import java.sql.Timestamp
import java.util.Date
object Gender extends Enumeration {
type Gender = Value
val MALE = Value("MALE")
val FEMALE = Value("FEMALE")
}
@d6y
d6y / IO.md
Created December 23, 2016 13:28
IO notes for Functional Brighton

IO

Basic concepts and mechanisms

  • pure functions, no side effects, good for reasoning
  • IO system separates pure functions from side-effects
  • Hello world, various ways to run it
  • putStrLn and getLine, do notation
  • Types of IO () and IO String
  • Reverse example, with IF and recursive call
@d6y
d6y / 116.md
Created November 18, 2016 10:16
CSP 116 notes
@d6y
d6y / pipe.txt
Created November 16, 2016 00:04
Haskell pipe
Prelude> let (|>) = flip (.)
Prelude> let hh = (*2) |> (+1) |> (+0.1)
Prelude> :t hh
hh :: Fractional c => c -> c
Prelude> hh 50
101.1
Prelude> :q
Leaving GHCi.
@d6y
d6y / example.scala
Created November 3, 2016 12:49
Alternative to Either[Error, Unit]
import scala.util.{Either, Right, Left}
object MarkerExample {
case class Error(msg: String)
sealed trait Success // or "NoValue" or "SuccessWithNoValue"?
object success extends Success {
override def toString: String = "success"
}
@d6y
d6y / lyah-fb2.md
Created November 2, 2016 08:57
Notes from Functional Brighton LYAHFGG Part II

Types and Typeclasses

NB: :{ and :} to paste blocks into GHCi.

Types

  • Every expression has a type known at compile time
  • Examine a type with :t
  • Common types: Int, Integer, Float, Double, Bool, Char
  • functions have types e.g., addThree
@d6y
d6y / pumpkin.md
Last active November 1, 2016 18:44
Notes for Dave

General comments you can ignore because they are not critical

  • We disagree over code formatting of plurals. I think we should only code format types and values that the reader could lookup. E.g., Hlists vs. HLists. Ditto for function names (flatMapping isn't a method I could find). I could drone on about this, but I'll spare you.

  • For links, we should settle on a house style: do we hyperlink the number in "Chapter 5" or the whole phrase. Looks like you have consistently used the number. So ignore this for now.


BTW, I've worked from the PDF. I have pasted text from the PDF: that sometimes goes wonky, but tried to fix this gist when I spot it.