This file contains 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
object Main extends App{ | |
trait Creatable[T] { | |
def create(): T | |
} | |
class Cat(val name: String) | |
// 自作の型への適用 | |
implicit object Cat extends Creatable[Cat] { | |
def create() = new Cat("taro") |
This file contains 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
object Main extends App{ | |
implicit val createValueInt: Int = 3 | |
implicit val createValueStrign: String = "po" | |
def createValue[T](implicit value: T) = value | |
val valueInt: Int = createValue | |
println(valueInt) | |
val valueString: String = createValue |
This file contains 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 ..< 100).forEach { | |
switch ($0 % 3, $0 % 5) { | |
case (0, 0): | |
print("FizzBuzz") | |
case (0, _): | |
print("Fizz") | |
case (_, 0): | |
print("Buzz") | |
default: | |
print($0) |
This file contains 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 info.biacco42.test.typeclass | |
/** | |
* Created by sanok on 2017/05/25. | |
*/ | |
trait Addable[T] { | |
val unit: T | |
def add(x: T, y: T): T |
This file contains 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
{-# LANGUAGE FlexibleInstances #-} | |
main = do | |
print $ mySum ([1, 2, 3] :: [Int]) | |
print $ mySum (["hoge", "piyo", "huga"] :: [String]) | |
class AddMonoid a where | |
unit :: a | |
add :: a -> a -> a |
This file contains 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
object FizzBuzz { | |
def main(args: Array[String]) { | |
val fizzbuzz = (1 to 100).map { i => | |
(i % 3, i % 5) match { | |
case (0, 0) => "fizzbuzz" | |
case (0, _) => "fizz" | |
case (_, 0) => "buzz" | |
case _ => i.toString | |
} | |
} |
This file contains 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
[alias] | |
graph = log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short | |
adda = add -A | |
addp = add -p | |
st = status | |
br = branch | |
co = checkout | |
cob = checkout -b | |
cm = commit -m | |
diffc = diff --cached |
This file contains 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
object Main extends App{ | |
// 真面目に書いた正格評価の fib seq | |
fib(10).foreach { println } | |
def fib(n: Int): Seq[Int] = { | |
assert(n > 0) | |
def rec(n: Int, a: Int, b: Int, seq: Seq[Int]): Seq[Int] = (n <= 1) match { | |
case true => seq | |
case false => rec(n - 1, b, a + b, seq :+ b) |
This file contains 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
object Main extends App { | |
val poPoption = Poption("Po") | |
val popoPoption = Poption("PoPo") | |
val popopo = for { | |
po <- poPoption | |
popo <- popoPoption | |
} yield { po + popo } | |
println(popopo) |
This file contains 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
object Main extends App{ | |
val forPo = new Forable("Po") | |
val po = for { | |
u <- forPo | |
} yield u | |
println(po) | |
// Kaboom! Cannot compile - lack of flatMap |
OlderNewer