SQL関数AVG、SUM、COUNTなどは単一行ではなく複数行を対象としている
ANSIとISOで規格化されている。
import java.util.*; | |
import java.util.stream.*; | |
public class Test { | |
public static void main(String... args) { |
fun main(args : Array<String>) { | |
println("はろーわーるど") | |
} |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.List; | |
import java.util.function.Function; | |
public class Recursive { | |
/** | |
* listを集計する奴 | |
* @param xs リスト |
import java.util.ArrayList | |
import java.util.Collections | |
public class Recursive { | |
public fun sum(xs:List<Int>):Int = if (xs.isEmpty()){0}else{val y_ys = headTail<Int>(xs);y_ys.first + sum(y_ys.second)} | |
public fun length(xs:List<Int>):Int = if (xs.isEmpty()){ 0 } else{val y_ys = headTail<Int>(xs); 1 + length(y_ys.second)} | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.Assert.assertThat; | |
import java.util.Arrays; | |
import java.util.List; | |
import org.junit.Test; | |
public class RecursiveTest { |
fun main(args : Array<String>) { | |
// コード5.2.2 タプルの各要素の型や値でパターンマッチング | |
val pair1 = Pair(1, 2) | |
when(pair1) { | |
//できない is #(0, 0) -> "(0, 0)" | |
// できない is #(0, Int) -> "(0, Int)" | |
// できない is #(Int, 0) -> "(Int, 0)" | |
is Pair<Int, Int> -> "(Int, Int)" // コンパイルレベルで自明 |
fun main(args : Array<String>) { | |
// JavaのFunctoinのSAMはこんな感じな気がする | |
val func = java.util.function.Function<Int, Int>{ a -> a + 1} | |
val result = func.apply(1) | |
println(result) | |
// こんなんも微妙 | |
val res = FuncExecutor("hogehoge").execute{ |
// この辺りを眺めながら書いている | |
// https://gist.github.com/gakuzzzz/8d497609012863b3ea50#functor | |
// https://github.com/backpaper0/sandbox/blob/master/functor-applicative-study/src/main/scala/functor-applicative-study.scala | |
// https://bitbucket.org/cocoatomo/categorical/src/ac1a9340e607abc1691dd9f07b9f8f253a418fd6/src/main/java/co/coatomo/math/categorical/typeclass/functor/FList.java?at=default&fileviewer=file-view-default | |
interface Function1<T> { | |
fun <B> apply(value: T): Functor<B> | |
} | |
interface Function2<T, R> : Functor<T> { |