This file contains hidden or 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
import scala.language.higherKinds | |
sealed trait TBool { | |
type Not <: TBool | |
type And[A <: TBool] <: TBool | |
type Or[A <: TBool] <: TBool | |
type If[Then <: T, Else <: T, T] <: T | |
} | |
class TTrue extends TBool { |
This file contains hidden or 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
(* Binary tree with leaves carrying an integer. *) | |
type tree = Leaf of int | Node of tree * tree | |
let rec exists_leaf test tree = | |
match tree with | |
| Leaf v -> test v | |
| Node (left, right) -> | |
exists_leaf test left | |
|| exists_leaf test right |
This file contains hidden or 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 HelloUniverse extends App { | |
implicit class RichList[T](self: List[T]) { | |
def mkStringIfNonEmpty[T](start: String, | |
seq: String, | |
end: String): String = | |
if (self.nonEmpty) self.mkString(start, seq, end) | |
else "" | |
} |
This file contains hidden or 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
std::sort(idols.begin(), idols.end(), | |
[](const Idol& lhs, const Idol& rhs){ return lhs.production_id < rhs.production_id; }); |
This file contains hidden or 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
import org.apache.spark.SparkContext | |
import org.apache.spark.mllib.clustering.KMeans | |
import org.apache.spark.mllib.linalg.Vectors | |
object KMeansIris extends App { | |
val context = new SparkContext("local", "demo") | |
val data = context. | |
textFile("src/main/resources/iris.data"). | |
filter(_.nonEmpty). |
This file contains hidden or 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 FFT extends App { | |
import breeze.linalg.DenseVector | |
import breeze.math.Complex | |
def fft(f: DenseVector[Complex]): DenseVector[Complex] = { | |
require( | |
(f.size == 0) || | |
math.pow(2, (math.log(f.size) / math.log(2)).round).round == f.size, | |
"size " + f.size + " must be a power of 2!") |
This file contains hidden or 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
#include <iostream> | |
#include <type_traits> | |
#include <boost/optional.hpp> | |
template < | |
typename Input, | |
typename Functor, | |
typename OptionalOutput = typename std::result_of<Functor(Input)>::type | |
> | |
OptionalOutput operator >>= ( |
This file contains hidden or 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
#include <algorithm> | |
#include <iostream> | |
#include <type_traits> | |
#include <vector> | |
template < | |
typename Input, // 引数から推論されるので省略可 | |
typename Functor, // 引数から推論されるので省略可 | |
typename Output = typename std::result_of<Functor(Input)>::type | |
> |
This file contains hidden or 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
sbt.version=0.13.2 |
NewerOlder