File tree Expand file tree Collapse file tree 2 files changed +106
-0
lines changed
Expand file tree Collapse file tree 2 files changed +106
-0
lines changed Original file line number Diff line number Diff line change @@ -802,6 +802,48 @@ public function
802802 return FALSE ;
803803 }
804804
805+ #[Meta \Date('2025-03-14 ' )]
806+ #[Meta \Info('Use a callable to check if the dataset has something. ' )]
807+ public function
808+ HasThing (callable $ FuncKeyValue ):
809+ bool {
810+
811+ $ K = NULL ;
812+ $ V = NULL ;
813+
814+ ////////
815+
816+ foreach ($ this ->Data as $ K => $ V ) {
817+ if ($ FuncKeyValue ($ K , $ V ))
818+ return TRUE ;
819+
820+ continue ;
821+ }
822+
823+ return FALSE ;
824+ }
825+
826+ #[Meta \Date('2025-03-14 ' )]
827+ #[Meta \Info('Use a callable to find an item in the dataset. ' )]
828+ public function
829+ FindThing (callable $ FuncKeyValue ):
830+ ?Units \KeyValue {
831+
832+ $ K = NULL ;
833+ $ V = NULL ;
834+
835+ ////////
836+
837+ foreach ($ this ->Data as $ K => $ V ) {
838+ if ($ FuncKeyValue ($ K , $ V ))
839+ return new Units \KeyValue ($ K , $ V );
840+
841+ continue ;
842+ }
843+
844+ return NULL ;
845+ }
846+
805847 public function
806848 IsFirstKey (mixed $ Key ):
807849 bool {
Original file line number Diff line number Diff line change 1+ <?php ##########################################################################
2+ ################################################################################
3+
4+ namespace Nether \Common \Units ;
5+
6+ use Nether \Common ;
7+
8+ ################################################################################
9+ ################################################################################
10+
11+ class KeyValue {
12+
13+ public string |int
14+ $ Key ;
15+
16+ public mixed
17+ $ Value ;
18+
19+ ////////////////////////////////////////////////////////////////
20+ ////////////////////////////////////////////////////////////////
21+
22+ public function
23+ __Construct (string |int $ Key , mixed $ Value ) {
24+
25+ $ this ->Key = $ Key ;
26+ $ this ->Value = $ Value ;
27+
28+ return ;
29+ }
30+
31+ ////////////////////////////////////////////////////////////////
32+ ////////////////////////////////////////////////////////////////
33+
34+ static public function
35+ FromKeyedPair (array $ KV ):
36+ static {
37+
38+ if (count ($ KV ) !== 1 )
39+ throw new Common \Error \FormatInvalid ('not a single item array ' );
40+
41+ ////////
42+
43+ return new static (key ($ KV ), current ($ KV ));
44+ }
45+
46+ static public function
47+ FromFlatPair (array $ KV ):
48+ static {
49+
50+ if (count ($ KV ) !== 2 )
51+ throw new Common \Error \FormatInvalid ('not a two item array ' );
52+
53+ if (!array_key_exists (0 , $ KV ))
54+ throw new Common \Error \FormatInvalid ('missing key 0 ' );
55+
56+ if (!array_key_exists (1 , $ KV ))
57+ throw new Common \Error \FormatInvalid ('missing key 1 ' );
58+
59+ ////////
60+
61+ return new static ($ KV [0 ], $ KV [1 ]);
62+ }
63+
64+ };
You can’t perform that action at this time.
0 commit comments