<?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>DEV Community: Poladarn</title>
    <description>The latest articles on DEV Community by Poladarn (@jituanlin).</description>
    <link>https://dev.to/jituanlin</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%2F246187%2F2a36eb03-1b64-464b-9829-d8822c6a9ae6.jpg</url>
      <title>DEV Community: Poladarn</title>
      <link>https://dev.to/jituanlin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jituanlin"/>
    <language>en</language>
    <item>
      <title>A light library for pipe style programming</title>
      <dc:creator>Poladarn</dc:creator>
      <pubDate>Fri, 11 Feb 2022 06:55:44 +0000</pubDate>
      <link>https://dev.to/jituanlin/a-light-library-for-pipe-style-programming-5dlh</link>
      <guid>https://dev.to/jituanlin/a-light-library-for-pipe-style-programming-5dlh</guid>
      <description>&lt;h1&gt;
  
  
  A light library for pipe style programming
&lt;/h1&gt;

&lt;p&gt;Pipe style programming is a powerful tool for dealing with data processing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ramdajs.com/" rel="noopener noreferrer"&gt;Ramda&lt;/a&gt; is the most popular library for that.&lt;/p&gt;

&lt;p&gt;And &lt;a href="https://github.com/gcanti/fp-ts" rel="noopener noreferrer"&gt;fp-ts&lt;/a&gt; also excels at that and provides many useful ADT(Algebraic Data Types).&lt;/p&gt;

&lt;p&gt;However, they may also introduce other things you don't want.&lt;/p&gt;

&lt;h2&gt;
  
  
  The price of Ramda
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Complex type definition.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Due to the dynamic nature of Ramda, TypeScript needs to work very hard to describe it and end up with a complex type definition.&lt;/p&gt;

&lt;p&gt;How many times have we needed to dig into the source type definition to find out&lt;br&gt;
why does type inference not work, even knowing that the logic of the code is correct?&lt;/p&gt;

&lt;p&gt;To me, TypeScript is more of an enemy than an assistant when I use Ramda.&lt;/p&gt;

&lt;p&gt;Ramda type definitions are fragile for several reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pipe&lt;/code&gt; function is designed to accept data as the last argument. That makes type inference difficult, especially when combined with overloaded functions.&lt;/li&gt;
&lt;li&gt;Currying. You can pass arguments in any way you like in Haskell. It's sweet but makes type description difficult.&lt;/li&gt;
&lt;li&gt;Function overload. Almost every function in Ramda is overloaded. TypeScript has difficulty choosing the right overload in the &lt;code&gt;pipe&lt;/code&gt; function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The price of fp-ts
&lt;/h2&gt;

&lt;p&gt;fp-ts is great but introduces many functional programming concepts that many teams are unfamiliar with.&lt;/p&gt;

&lt;p&gt;That makes team collaboration may require too much learning cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  pipeable-es-fns maybe another choice
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/jituanlin/pipeable-es-fns" rel="noopener noreferrer"&gt;pipeable-es-fns&lt;/a&gt; proposes another solution:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Embrace pipe style programming.&lt;/li&gt;
&lt;li&gt;Simple type definition is easy to understand and debug.&lt;/li&gt;
&lt;li&gt;It just ports ES6+ functions to curried version, that's all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The idea of pipeable-es-fns is to introduce minimal things for adopting pipe style programming.&lt;/p&gt;

&lt;p&gt;Instead of selling &lt;em&gt;point free style&lt;/em&gt; or &lt;em&gt;Monad&lt;/em&gt; to the team, it should be easier to convince a team to use the curried ES6+ function.&lt;/p&gt;

&lt;h3&gt;
  
  
  Design philosophy
&lt;/h3&gt;

&lt;p&gt;pipeable-es-fns adopts a few design philosophies to make type and usage smooth:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Just curried the ES6+ functions and try to keep others untouched.&lt;/li&gt;
&lt;li&gt;Just use the TypeScript official type definitions of ES6+ functions.&lt;/li&gt;
&lt;li&gt;Just delegate the implementation to the native ES6+ functions for avoiding runtime.&lt;/li&gt;
&lt;li&gt;Unlike Ramda, the pipe function accepts data as its first argument for better type inference.&lt;/li&gt;
&lt;li&gt;Organize the functions in a namespace rather than function overload for better type inference.&lt;/li&gt;
&lt;li&gt;Doesn't support deprecated methods intentionally.&lt;/li&gt;
&lt;li&gt;Encourage to specify the optional arguments implicitly.&lt;/li&gt;
&lt;li&gt;Encourage to use one function in one way only.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>typescript</category>
      <category>functional</category>
      <category>ramda</category>
      <category>lib</category>
    </item>
  </channel>
</rss>
