Skip to content

Commit 5789968

Browse files
ircmaxellircmaxell
authored andcommitted
Switch unit to being static
1 parent 8e8f929 commit 5789968

File tree

15 files changed

+11
-12
lines changed

15 files changed

+11
-12
lines changed

.gitignore

100644100755
File mode changed.

README.md

100644100755
File mode changed.

composer.json

100644100755
File mode changed.

lib/MonadPHP/Chain.php

100644100755
File mode changed.

lib/MonadPHP/Deferred.php

100644100755
File mode changed.

lib/MonadPHP/Identity.php

100644100755
File mode changed.

lib/MonadPHP/ListMonad.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function bind($function, array $args = array()) {
1616
foreach ($this->value as $value) {
1717
$result[] = $this->runCallback($function, $value, $args);
1818
}
19-
return $this->unit($result);
19+
return $this::unit($result);
2020
}
2121

2222
public function extract() {
@@ -31,4 +31,4 @@ public function extract() {
3131
return $ret;
3232
}
3333

34-
}
34+
}

lib/MonadPHP/Maybe.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public function bind($function){
88
if (!is_null($this->value)) {
99
return parent::bind($function);
1010
}
11-
return $this->unit(null);
11+
return $this::unit(null);
1212
}
1313

14-
}
14+
}

lib/MonadPHP/Monad.php

100644100755
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ public function __construct($value) {
1010
$this->value = $value;
1111
}
1212

13-
public function unit($value) {
14-
if ($value instanceof $this) {
13+
public static function unit($value) {
14+
if ($value instanceof static) {
1515
return $value;
1616
}
17-
$class = get_class($this);
18-
return new $class($value);
17+
return new static($value);
1918
}
2019

2120
public function bind($function, array $args = array()) {
22-
return $this->unit($this->runCallback($function, $this->value, $args));
21+
return $this::unit($this->runCallback($function, $this->value, $args));
2322
}
2423

2524
public function extract() {
@@ -37,4 +36,4 @@ protected function runCallback($function, $value, array $args = array()) {
3736
return call_user_func_array($function, $args);
3837
}
3938

40-
}
39+
}

lib/MonadPHP/Promise.php

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function __construct($success = null, $failure = null) {
1616
$this->failure = $failure;
1717
}
1818

19-
public function unit($success = null, $failure = null) {
19+
public static function unit($success = null, $failure = null) {
2020
return new Promise($success, $failure);
2121
}
2222

@@ -49,4 +49,4 @@ protected function resolve($status, $value) {
4949
public function when($success = null, $failure = null) {
5050
return $this->bind($success, $failure);
5151
}
52-
}
52+
}

0 commit comments

Comments
 (0)