<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Tom</title>
    <description>The latest articles on Forem by Tom (@tkx).</description>
    <link>https://forem.com/tkx</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1180795%2Fbdc1b86d-2301-4e9d-9def-018bc23a0338.jpeg</url>
      <title>Forem: Tom</title>
      <link>https://forem.com/tkx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/tkx"/>
    <language>en</language>
    <item>
      <title>Why PHP? Thoughts…</title>
      <dc:creator>Tom</dc:creator>
      <pubDate>Sat, 25 Nov 2023 11:17:40 +0000</pubDate>
      <link>https://forem.com/tkx/why-php-thoughts-266j</link>
      <guid>https://forem.com/tkx/why-php-thoughts-266j</guid>
      <description>&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/robertobutti"&gt;@robertobutti&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.to/robertobutti/why-php-2e4h"&gt;https://dev.to/robertobutti/why-php-2e4h&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Read this article; here are some thoughts on the subject.&lt;br&gt;
PHP will never ever be on par with python because these three reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;No native SET data structure support, which is a direct proof that php never was designed for data programming. Amazing &lt;a class="mentioned-user" href="https://dev.to/krakjoe"&gt;@krakjoe&lt;/a&gt; and friends introduced it only in 2016 in Ds pecl extension, while python have had it from start.&lt;br&gt;
Consider algorithmic problems such as leetcode stuff, php developer would struggle in half of them not thinking data first - with set structure being a solution in half of this half. Famous expression - framework is not the way you code, it is the way you think. Same situation here. Programming language is not the way you code - but how you think as a programmer, what is your approach, etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No native coroutine/async/await support in php. Same situation, only adopting ReactPHP/Swoole would give you this instrument, although you’ll have to struggle implementing async solutions for common jobs like databases, etc. And core php team never thought of that in the first place, why?&lt;br&gt;
To create python’s FastAPI stuff you’ll have first to invent it with only Swoole being native implementation of the approach, still it is an external library.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multithreading? Forget it. No native support as well. First thing I had to do as a math student 30 years ago was to implement rectangles method multithreadingly. Guess what, you can’t do it in php.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Funny story is that I never hesitated which language to choose, PHP was there for me right away :)&lt;br&gt;
And I am not trying to start a hate topic. I only think that one should be realistic and aware about cans and cannots with this or that instrument.&lt;/p&gt;

&lt;p&gt;K! THX! BYE!&lt;/p&gt;

</description>
      <category>php</category>
    </item>
    <item>
      <title>PHP Array And Objects Streaming Library</title>
      <dc:creator>Tom</dc:creator>
      <pubDate>Tue, 10 Oct 2023 11:39:55 +0000</pubDate>
      <link>https://forem.com/tkx/php-array-and-objects-streaming-library-2d1l</link>
      <guid>https://forem.com/tkx/php-array-and-objects-streaming-library-2d1l</guid>
      <description>&lt;p&gt;Have you ever found yourself in the situation when you need to evaluate and transform some data which is in a list, basically filter-map-reducing it? It's an everyday job! Somehow PHP doesn't have prebuilt Array API like does Javascript or Java, which is a very convenient way to chain your operations, and by the way it should be lazy - which means not traversing your data in every chained function. Instead it would stack your calls and then dump it to terminal operation when it is time.&lt;/p&gt;

&lt;p&gt;I mean something like this, and imagine there are millions of traversables there (written in pseudo-js-code):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;dataArray&lt;/span&gt; &lt;span class="c1"&gt;// a lot of records from database&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// must have "subData"&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// extract "subData"&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;sd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="nx"&gt;sd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// must have "user"&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;sd&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// extract "user"&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// collect extracted users&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;money&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;days&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; 
    &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="c1"&gt;// add some 'total' to each user&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;groupBy&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// somehow group users&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mapAll&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// transform all groups&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduceAll&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// sum values in groups&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// and finally get the result&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nice and clear!&lt;br&gt;
However in PHP it is impossible unless you dig the web to find something suitable.&lt;/p&gt;

&lt;p&gt;Welcome &lt;a href="https://github.com/tkx/stream"&gt;PHP Stream API&lt;/a&gt; - heavily inspired by Java Stream API and enriched by Underscore methods - convenient array mutation and filtering conveyor, that takes the pain of working with traversables in PHP.&lt;/p&gt;

&lt;p&gt;Fork, test, comment, like, subscribe, ring the bell (joke) :)&lt;br&gt;
It is not final, but together we can make it the best!&lt;/p&gt;

&lt;p&gt;I'll be adding some reasonable stuff while using it in my everyday job if something comes up my mind.&lt;/p&gt;

&lt;p&gt;K! THX! BYE!&lt;/p&gt;

</description>
      <category>php</category>
      <category>array</category>
      <category>library</category>
    </item>
  </channel>
</rss>
