Diffs
Sequence/trunk/test/seq.php
@@ -1,6 +1,6 @@
<?php
include_once dirname(__FILE__) . '/tool/lime.php';
-include_once dirname(__FILE__) . '/../src/seq.php';
+include_once dirname(__FILE__) . '/../code/Sequence.php';
$lime = new lime_test;
////////////////////////////////////////////////////////////////////////////////
@@ -62,7 +62,6 @@
$lime->is(count($seq), 2);
$seq->lengthen(4);
$lime->is(count($seq), 4);
-d($seq->toArray());
$lime->is($seq[-1], null);
////////////////////////////////////////////////////////////////////////////////
@@ -364,12 +363,6 @@
////////////////////////////////////////////////////////////////////////////////
-$lime->comment('product');
-$seq = seq(1, 2, 3);
-$lime->is($seq->product(), 6);
-
-////////////////////////////////////////////////////////////////////////////////
-
$lime->comment('sum');
$seq = seq(1, 2, 3, 4, 5);
$lime->is($seq->sum(), 15);
Sequence/trunk/code/Sequence.php
@@ -429,39 +429,21 @@
return $seq;
}
- /**
- * リストの要素をすべてvar_dumpする
- *
- * @return Sequence
- */
- function dump()
- {
- echo 'seq(' . PHP_EOL;
- foreach ($this->arr as $i => $elt) {
- $elt instanceof self ? $elt->dump() : var_dump($elt);
- if ($i !== $this->count() - 1) echo ',' . PHP_EOL;
- }
- echo ')' . PHP_EOL;
- return $this;
- }
/**
* リストの要素をひとつずつ与えられた関数に適用し、
* その結果を格納したリストを生成する
*
* @param callback $func
- * @param unknown_type ...
* @return Sequence
*/
function map($func)
{
$this->assertCallable($func);
- $args_proto = $this->buildArgsProto(func_get_args());
$ret = seq();
foreach ($this as $elt) {
- $args = array_merge($args_proto, array($elt));
- $ret->push(call_user_func_array($func, $args));
+ $ret->push(call_user_func($func, $elt));
}
return $ret;
}
@@ -471,18 +453,15 @@
* その結果がtrueである要素を格納した新たなリストを生成する
*
* @param callback $func
- * @param unknown_type ...
* @return Sequence
*/
function filter($func)
{
$this->assertCallable($func);
- $args_proto = $this->buildArgsProto(func_get_args());
$ret = seq();
foreach ($this as $elt) {
- $args = array_merge($args_proto, array($elt));
- if (call_user_func_array($func, $args)) $ret->push($elt);
+ if (call_user_func($func, $elt)) $ret->push($elt);
}
return $ret;
}
@@ -513,11 +492,9 @@
function all($func)
{
$this->assertCallable($func);
- $args_proto = $this->buildArgsProto(func_get_args());
foreach ($this as $elt) {
- $args = array_merge($args_proto, array($elt));
- if (!call_user_func_array($func, $args)) return false;
+ if (!call_user_func($func, $elt)) return false;
}
return true;
}
@@ -530,11 +507,9 @@
function any($func)
{
$this->assertCallable($func);
- $args_proto = $this->buildArgsProto(func_get_args());
foreach ($this as $elt) {
- $args = array_merge($args_proto, array($elt));
- if (call_user_func_array($func, $args)) return true;
+ if (call_user_func($func, $elt)) return true;
}
return false;
}
@@ -548,11 +523,9 @@
function each($func)
{
$this->assertCallable($func);
- $args_proto = $this->buildArgsProto(func_get_args());
foreach ($this as $elt) {
- $args = array_merge($args_proto, array($elt));
- call_user_func_array($func, $args);
+ call_user_func($func, $elt);
}
return $this;
}
@@ -561,16 +534,8 @@
{
if (!is_callable($func)) throw new InvalidArgumentException;
}
+
- protected function buildArgsProto(Array $arr)
- {
- if (count($arr) > 1) {
- array_shift($arr);
- return $arr;
- }
- return array();
- }
-
/**
* リストをarrayにして返す
*
@@ -625,7 +590,7 @@
*/
function repeat($i)
{
- if (!is_int($i) || $i < 1) throw new InvalidArgumentException();
+ if (!is_int($i) || $i < 1) throw new InvalidArgumentException('first argument must be integer');
$arr = array();
for (; $i > 0; $i--) $arr[] = $this->arr;
@@ -633,7 +598,7 @@
}
/**
- * リストがある要素を持っているかどうかを返す
+ * リストがある要素を持っているかどうかを返す。比較は===で為される
*
* @param unknown_type $elt
* @return bool
@@ -702,7 +667,7 @@
$ret->append($elt);
}
else {
- throw new RuntimeException;
+ throw new InvalidArgumentException('argument must be Sequence');
}
return $ret;
}
属性に変更があったパス: Sequence/trunk
___________________________________________________________________
変更: svn:ignore
- docget.bat
doc
docgen.bat
+ docget.bat
doc
docgen.bat
.*