Skip to content

Instantly share code, notes, and snippets.

(defproject update-tweets "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
[org.twitter4j/twitter4j-core "3.0.4"]]
:jvm-opts ["-Dtwitter4j.oauth.consumerKey="
"-Dtwitter4j.oauth.consumerSecret="])

!SLIDE PartialFunction ってなあに?

部分関数のことだよ

!SLIDE 部分関数ってなあに?

そもそも関数ってなあに?

import scalaz._, Scalaz._
sealed trait MyOption[+A]
case class MySome[A](value: A) extends MyOption[A]
case object MyNone extends MyOption[Nothing]
object MyOption {
implicit object MyOptionFunctor extends Functor[MyOption] {
import scalaz._,Scalaz._
val fizzbuzz = (x:Int) => (Enum[Int].from(0) map {n => ((n%3 === 0).option("Fizz") |+| (n%5 === 0).option("Buzz")) <+> n.shows.pure[Option]} take x+1 flatten).foreach(println)
@halcat0x15a
halcat0x15a / aaa.scala
Created July 23, 2012 03:45 — forked from gkojax/aaa.scala
case文とtry catchがネストしてるの
import scala.util.control.Exception._
def string2Int(sizeString: Option[String]): Option[Int] =
sizeString flatMap (a => allCatch opt a.toInt)
string2Int(Option("123")) // Some(123)
string2Int(Option("rrr")) // None
string2Int(None) // None
@halcat0x15a
halcat0x15a / App.scala
Created June 1, 2012 00:05 — forked from nisshiee/App.scala
ReaderをIterateeで扱う
import java.io.{ Reader, FileReader }
import scalaz._, Scalaz._
import effect._, IO._
import iteratee._, Iteratee._
object App extends SafeApp{
val separator = sys.props("line.separator").head
override def run(args: ImmutableArray[String]): IO[Unit] = {
// Inversefizzbuzz
// http://www.jasq.org/2/post/2012/05/inverse-fizzbuzz.html
//
// fork from https://gist.github.com/2699068
import scalaz._
import Scalaz._
object InverseFizzbuzz extends App {
@halcat0x15a
halcat0x15a / gist:2383148
Created April 14, 2012 09:29 — forked from gakuzzzz/gist:2383028
計算中と計算終了を表すコンテナ
trait Container[+R, +C] {
def map[A](f: C => A): Container[R, A]
def flatMap[RR >: R, A](f: C => Container[RR, A]): Container[RR, A]
def toResult[RR >: R](implicit ev: C <:< RR): Result[RR]
}
case class Calculating[+R, +C](element: C) extends Container[R, C] {
@halcat0x15a
halcat0x15a / KanjiNumberParser.scala
Created December 18, 2011 08:12 — forked from tototoshi/KanjiNumberParser.scala
漢数字パーサだよ
import scalaz._
import Scalaz._
import scala.util.parsing.combinator._
object KanjiNumberParser extends RegexParsers {
def one = "一" ^^^ digits(1)
def two = "二" ^^^ digits(2)
def three = "三" ^^^ digits(3)
def four = "四" ^^^ digits(4)
@halcat0x15a
halcat0x15a / a.scala
Created September 4, 2011 19:34
ScalazでIteratee
sealed trait StreamG[+E]
case object Empty extends StreamG[Nothing]
case class El[E](el: E) extends StreamG[E]
case object EOF extends StreamG[Nothing]
sealed trait IterV[+E, +A]