@@ -23,6 +23,18 @@ Although all of them are available with helper function `underscore($data)` or `
23
23
the methods are grouped and organized in different heriarchy and classes according as their scope.
24
24
This keeps it maintainable and saves from having a God class.
25
25
26
+ #### Contents
27
+
28
+ - [ Underscore] ( #underscore )
29
+ - [ UnderscoreFunction] ( #underscorefunction )
30
+ - [ UnderscoreArray] ( #underscorearray )
31
+ - [ UnderscoreCollection] ( #underscorecollection )
32
+ - [ UnderscoreBase] ( #underscorebase )
33
+ - [ HigherOrderMessage] ( #higherordermessage )
34
+ - [ ArrayAccess] ( #arrayaccess )
35
+ - [ Arrayizes] ( #arrayizes )
36
+
37
+
26
38
---
27
39
### Underscore
28
40
@@ -865,6 +877,56 @@ Alias of <a href="#unique">unique()</a>.
865
877
866
878
Alias of <a href =" #difference " >difference()</a >.
867
879
880
+ ---
881
+ ### HigherOrderMessage
882
+
883
+ A syntatic sugar to use elegant shorthand oneliner for complex logic often wrapped in closures.
884
+ See example below:
885
+
886
+ ``` php
887
+ // Higher Order Messaging
888
+ class HOM
889
+ {
890
+ protected $n;
891
+ public $square;
892
+
893
+ public function __construct($n)
894
+ {
895
+ $this->n = $n;
896
+ $this->square = $n * $n;
897
+ }
898
+
899
+ public function even()
900
+ {
901
+ return $this->n % 2 === 0;
902
+ }
903
+ }
904
+
905
+ $u = [new HOM(1), new HOM(2), new HOM(3), new HOM(4)];
906
+
907
+ // Filter `even()` items
908
+ $evens = $u->filter->even(); // 'even()' method of each items!
909
+
910
+ // Map each evens to their squares
911
+ $squares = $evens->map->square; // 'square' prop of each items!
912
+ // Gives an Underscore instance
913
+
914
+ // Get the data
915
+ $squares->get();
916
+ // [1 => 4, 3 => 16]
917
+ ```
918
+
919
+ Without higher order messaging that would look like:
920
+
921
+ ``` php
922
+ $evens = $u->filter(function ($it) {
923
+ return $it->even();
924
+ });
925
+
926
+ $squares = $evens->map(function ($it) {
927
+ return $it->square;
928
+ });
929
+ ```
868
930
869
931
---
870
932
### \ArrayAccess
0 commit comments