]> git.andy128k.dev Git - missing-tools.git/commitdiff
remove array fluent api
authorAndrey Kutejko <andy128k@gmail.com>
Wed, 31 Dec 2014 09:47:01 +0000 (11:47 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Wed, 31 Dec 2014 09:47:01 +0000 (11:47 +0200)
src/array.php

index f2f38f7cf786d4cb3eb04e8573ebbcffab245001..39e03e3a001db7fcdd728e02e38f138c70ab83de 100644 (file)
@@ -2,86 +2,8 @@
 
 namespace PFF;
 
-use \PFF\Symbol as S;
-
-final class Arr implements \ArrayAccess
+final class Arr
 {
-    private $arr;
-
-    public function __construct($arr)
-    {
-        $this->arr = $arr;
-    }
-
-    public static function create($arr)
-    {
-        return new self($arr);
-    }
-
-    public function arr()
-    {
-        return $this->arr;
-    }
-
-    public function map(/* $func, ... $args */)
-    {
-        $args = func_get_args();
-        $func = array_unshift($args);
-        $pos = array_search(S::_(), $args, true);
-        if (!$pos)
-            $pos = 0;
-
-        $result = array();
-        foreach ($this->arr as $item) {
-            $args[$pos] = $item;
-            $result[] = call_user_func_array($func, $args);
-        }
-
-        return new self($result);
-    }
-
-    public function pluck($key)
-    {
-        $result = array();
-        foreach ($this->arr as $item)
-            $result[] = is_object($item) ? $item->$key : $item[$key];
-        return new self($result);
-    }
-
-    /* strings */
-
-    public function join($separator)
-    {
-        return implode($separator, $this->arr);
-    }
-
-    /* ArrayAccess */
-
-    public function offsetSet($offset, $value)
-    {
-        if (is_null($offset))
-            $this->arr[] = $value;
-        else
-            $this->arr[$offset] = $value;
-    }
-
-    public function offsetExists($offset)
-    {
-        return isset($this->arr[$offset]);
-    }
-
-    public function offsetUnset($offset)
-    {
-        unset($this->arr[$offset]);
-    }
-
-    public function offsetGet($offset)
-    {
-        return isset($this->arr[$offset]) ? $this->arr[$offset] : null;
-    }
-
-    /* */
-
     public static function get($array, $key, $default=null)
     {
         if (array_key_exists($key, $array))
@@ -123,5 +45,13 @@ final class Arr implements \ArrayAccess
         });
         return $result;
     }
+
+    public static function pluck($array, $key)
+    {
+        $result = array();
+        foreach ($array as $item)
+            $result[] = is_object($item) ? $item->$key : $item[$key];
+        return $result;
+    }
 }