部分関数のことだよ
そもそも関数ってなあに?
(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="]) |
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) |
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 |
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 { |
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] { |
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) |
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] |