Skip to content

Instantly share code, notes, and snippets.

@akanehara
akanehara / Rot13.hs
Created January 31, 2013 02:29
すごいHaskell読書会 in 大阪 #4 第6章「モジュール」持ち寄り練習問題 解答例
module Toy.Rot13 (encrypt) where
import Data.Char
lowerA = ord 'a'
lowerZ = ord 'z'
upperA = ord 'A'
upperZ = ord 'Z'
@akanehara
akanehara / Parupunte.hs
Last active December 12, 2015 00:09
すごいHaskell読書会 in 大阪 #4 @Nushio さん問題にたいする答案
module Parupunte ((+), (*)) where
import qualified Prelude
(+) = (Prelude.*)
(*) = (Prelude.+)
@akanehara
akanehara / filter.php
Created February 7, 2013 08:59
selectManyWith を使った filter (ただの曲芸)
<?php
Ginq::range(1,10)
->selectManyWith(
function($x) { if ($x % 2 == 0) return [null]; else return []; },
function($x) { return $x; });
@akanehara
akanehara / memoize.php
Last active December 12, 2015 06:49
GinqにMemoizeIterator があれば…
<?php
// 巻き戻しできないデータソース
function dbFetch() {
...
yield $row;
...
}
// ごにょごにょしたのをメモ化
// もちろんこの段階ではまだ何も起らない
@akanehara
akanehara / DefaultEqualityComparer.php
Last active December 14, 2015 04:28
Ginqのデフォルトの同値比較の動作はこれでいいだろうか? distinct や groupBy で使われる予定。
<?php
class DefaultEqualityComparer implements EqualityComparer
{
public function equals($v0, $v1, $k0, $k1)
{
// オブジェクト
// (==) に委譲
// 同一でなく同値。全フィールドが一致?
if (is_object($v0) && is_object($v1)) {
@akanehara
akanehara / gist:5047584
Created February 27, 2013 12:28
Ginqのtoなんとか系整理案
<?php
/**
* toDictonary
* 廃止
* @deprecated
* @param \Closure $valueSelector
* @param \Closure $keySelector
* @param \Closure $combiner
* @return array
{-# LANGUAGE XNoMonomorphismRestriction #-}
import Control.Monad
newtype Foo m a b = Foo (m a -> (a -> m b))
instance (Monad m) => Monoid (Foo m a b) where
mempty = return
mappend x y = x <=< y
@akanehara
akanehara / equalitycompare.php
Created March 18, 2013 12:14
この equals() と hash() は矛盾しないよね?よね?
<?php
public function equals($v0, $v1)
{
if (is_array($v0) && is_array($v1)) {
return $v0 === $v1;
// 配列
// キーと値すべてが一致
}
if (is_object($v0) && is_object($v1)) {
return $v0 == $v1;
interface Decoder<A> {
decode(source: string): A;
}
class NumDecoder implements Decoder<Number> {
decode(source: string): Number {
return Number(source.trim());
}
}
@akanehara
akanehara / gist:6621103
Last active December 23, 2015 10:19
Yiiのアクティブレコード。問い合わせ上で導出できる論理属性の追加はこれじゃだめ?
<?php
/**
* @property float $x_of_pos
* @property float $y_of_pos
*/
class GlobalPosition
{
public $x_of_pos;
public $y_of_pos;