Skip to content

Instantly share code, notes, and snippets.

@Gab-km
Gab-km / fizzbuzz.scala
Last active August 29, 2015 14:00
Scala で Active Patterns っぽいことやってみた
class FizzBuzzExtractor[T](f: T => Boolean){
def unapply(t: T) = f(t)
}
val FizzBuzz = new FizzBuzzExtractor[Int](_ % 15 == 0)
object Fizz extends FizzBuzzExtractor[Int](_ % 3 == 0)
object Buzz extends FizzBuzzExtractor[Int](_ % 5 == 0)
object FizzBuzzRunner {
def run(num: Int) = num match {
@Gab-km
Gab-km / 00_fsharp_tips_for_newbies.rst
Last active August 29, 2015 14:00
F# Tips inspired by @kmizu's Scala Tips for newbies

これは、 @kmizu さんの「初学者向けの Scala Tips」を勝手に F# にポートした記事です。

@Gab-km
Gab-km / Callable.fs
Last active August 29, 2015 14:01
This is a sample implementation of Callable in F#.
// Interface
type ICallable<'a, 'b> =
abstract member callback: 'a -> 'b
// concrete class
type Callable<'a, 'b>(f: 'a -> 'b) =
interface ICallable<'a, 'b> with
member self.callback x = f x
// computation builder
@Gab-km
Gab-km / mongodb.ps1
Created June 3, 2014 11:32
MongDB の C# Driver を PowerShell から使ってみた
[System.Reflection.Assembly]::LoadFile('/path/to/MongoDB.Driver.dll')
[System.Reflection.Assembly]::LoadFile('/path/to/MongoDB.Bson.dll')
$client = New-Object MongoDB.Driver.MongoClient("mongodb://hostname")
$server = $client.GetServer()
$db = $server.GetDatabase("test")
$user = $db.GetCollection("User")
foreach($doc in $user.FindAll() {
[System.Console]::WriteLine($doc)
@Gab-km
Gab-km / mailboxProcessorSample.fs
Created August 6, 2014 08:25
MailboxProcessor<'Message> の調べ物
type Message = string * AsyncReplyChannel<string>
let agent = new MailboxProcessor<Message>(fun inbox ->
let rec loop count =
async {
System.Threading.Thread.Sleep(1000) // something busy
let! msg, replyChannel = inbox.Receive()
printfn "%s" msg
replyChannel.Reply(msg + msg)
return! loop (count + 1)
namespace FsCheck.Ext
module Test =
open System
open FsCheck
open FsCheck.Arb
type JapaneseChar = char
let japaneseChar (s: string) =
@Gab-km
Gab-km / concurrentProgramming_head.rst
Last active August 29, 2015 14:07
公式チュートリアルである "Getting Started with Erlang User's Guide" の翻訳 - Concurrent Programming (翻訳中)
@Gab-km
Gab-km / dict.py
Last active August 29, 2015 14:07
2つの dict の和を取る関数(キー重複は後勝ち)
def add_dict(this, other):
"""2つの dict の和を取る関数(キー重複は後勝ち)
@this ベースとなる dict オブジェクト
@other 追加される dict オブジェクト
@return 2つの dict を合成した dict
"""
result = this.copy()
for key in other:
result[key] = other[key]
return result
@Gab-km
Gab-km / Adder.java
Created October 20, 2014 13:47
高階関数とインターフェイス
class Adder implements Applyable {
@override
public int func(int a, int b) {
return a + b;
}
}
@Gab-km
Gab-km / Applyable.java
Last active August 29, 2015 14:07
カリー化とインターフェイス
// TVar -> TResult
interface Applyable<TVar, TResult> {
public abstract TResult apply(TVar variable);
}