<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aarsh Shah on Medium]]></title>
        <description><![CDATA[Stories by Aarsh Shah on Medium]]></description>
        <link>https://medium.com/@aarshkshah1992?source=rss-54aaaf1913a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YxYtJcfbB-wogLEK.jpg</url>
            <title>Stories by Aarsh Shah on Medium</title>
            <link>https://medium.com/@aarshkshah1992?source=rss-54aaaf1913a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 04:12:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aarshkshah1992/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I name thee solitude]]></title>
            <link>https://medium.com/@aarshkshah1992/i-name-thee-solitude-c7bd0c1d4ab3?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7bd0c1d4ab3</guid>
            <category><![CDATA[loneliness]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Wed, 08 Feb 2023 13:26:50 GMT</pubDate>
            <atom:updated>2023-02-08T13:26:50.688Z</atom:updated>
            <content:encoded><![CDATA[<p>There are no extents to which we humans will not go to to escape from our own loneliness. Addiction, toxic relationships, friendships based on convenience, internet, drugs, savior complex, ego, anything and everything to feed the devil. A devil with an insatiable appetite. Can we make peace with our own loneliness ? Can we just accept, at a very primal fundamental level that we humans are innately alone, that life is meant to be that way, can we make peace with that devil, can we make love to it, can we thrive with it ? I know, I know, human connections are the way to a meaningful life, that breaking through the barriers of that self imposed loneliness is a humane task required of us by existence, but can I stop using people to fill my own loneliness ? Can people be a source of nourishment instead of fodder to this devil of innate loneliness ? A dessert, that ice cream that is eaten for joy rather than to satiate hunger ? Imagine a life, where I am happy to be, where I respect myself for who I am, where the efforts I make are for nourishment, not for escape, where the relationships I build are to enjoy the joys of human companionship, not to fill some hole within. That is an ideal life. “Oh loneliness, I know you are there. I know you live within, eating all that I value, constantly scaring me to run away from you lest I see you in your naked weak form and see how powerless you truly are, but I will not be scared. I will make peace with you. We shall live as brothers, with me nurturing you, but not fattening you. You have to understand that while I have nothing but empathy for you, I too want to live a life outside of you. That I , a human, have my own aspirations, my own desire to seek meaning, my own moral pursuit of joy and happiness. Must you keep impeding me ? Let me go, I will return, but return as a happy friend so that we shall dance together and I shall name thee solitude.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7bd0c1d4ab3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Internal Ramblings on a solo Chile trip]]></title>
            <link>https://medium.com/@aarshkshah1992/internal-ramblings-on-a-solo-chle-trip-cd06846692fe?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd06846692fe</guid>
            <category><![CDATA[patagonia]]></category>
            <category><![CDATA[ramblings]]></category>
            <category><![CDATA[chile]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Mon, 06 Feb 2023 16:43:46 GMT</pubDate>
            <atom:updated>2023-02-06T16:50:23.541Z</atom:updated>
            <content:encoded><![CDATA[<p>Some pics from a month and a half long solo Chile and Patagonia trip. Did a lot of whitewater kayaking, became a better kayaker(better than I was before, I am still mostly shit and can’t roll back up in big waves) and paddled some good Class III rapids, hiked up volcanoes, glaciers and lakes, did sea kayaking, met some pretty interesting and kickass people travelling the world for years at end, lived in hostel dorm rooms and in campsites with waiters, tour guides, raft guides, broke students and lift mechanics, survived on canned chickpeas and rice for weeks (the trappings of being perhaps the only vegetarian in Southern Patagonia..), took some long showers using a handwash, ate plain rice with salsa sauce for dinners(pretty damn good), used my fluent Spanish to have deep meaningful conversations about Bollywood and cows with the curious Chileans who gave me lifts and rides when the buses were full, lived on a farm and befriended a lot of sheep and chicken and realised I love my homely comforts, food, friends and people more than I thought. I think this running away from my friends , family, love and job will now be a periodic affair because it makes me truly appreciate how important these people &amp; things are for me and how much value they add to my life without falling into the trappings of taking them for granted. I legit cried when I got some masala chai and biryani after a month and a half.</p><p>Also, the world is an insanely beautiful place. The creator has gone all in, no holds barred without any self doubt or creator’s block and the resulting artistry is majestic, sheer grandeur that will tell you in no uncertain terms what a piece of shit you are. Big waves will turn your boat irrespective of your social status/Managing Director post/networth if you miss a paddle stroke, the volcanoes will burn you alive if you come in their way, the sea waves will flip your sea kayak and carry you for miles while they decide your fate, the glaciers will claim you for their own with their crevasses if you are not present in the moment and do not give them the respect they deserve. On the other side of realising how insignificant I am and how little I matter, lies sheer joy and freedom and beauty, because I realise how low the stakes are and how beautifully trivial my life is. Any experience of sheer happiness and joy needs to be preceeded by ego death and that’s one of the best product this drug dealer called nature provides.</p><p>Happiness is a moral responsibility. It is immoral to be sad in a world so beautiful and with so many possibilities if you have good friends, a loving family and a good job that can pay for all of the above. Will constantly need a periodic reminder to not get caught up in the promotion -&gt; pay rise -&gt; bigger house -&gt; bigger car -&gt; neighbour has bigger house -&gt; therefore promotion -&gt; pay rise rat race cycle. Will need to stop complaining about any or all problems I have because I have it pretty good and complaining inspite of having it so good and in the face of so much beauty just might piss off the powers that be and make me come across as a thankless twat. It is death. Easier said than done as taming my rat racy tendencies is hard and I am a child of my culture &amp; environment after all(look at me shifting blame on the classic boogeyman called upbringing hah). Having said that, making money seems to be important to afford experiences such as these. There are ofcourse ways to experience all this without money by making yourself completely vulnerable and surrendering yourself to fate and the kindness of those around you but I do not have the courage or the inclination for that experiment, maybe my kid will try it someday.</p><p>The other big realisation is that to truly get empathy from others, you first have to make yourself vulnerable. Anyone who lives life like they got it all together is a fucking idiot and is missing out on a whole realm of human experience coloured by the beautiful colours of human empathy. When you make yourself vulnerable, people will try and help you, but you first have to surrender to your environment and to the humans around you. Sure, some people will take advantage of you or reject you but really, it’s a small visitors fee to pay to then experience the majestic garden of human kindness. So go stand in the sun for two hours to get that hitchike even though 10 cars reject you before the 11th one says yes, talk to strangers in your hostel and join random groups even though you are afraid you wont fit in/have anything in common, go tell that stranger that you’ve run out of rice and if you can borrow theirs, go tell that Spanish river guide that you are feeling unbelievably lonely and if he can just sit and have a chat with you in broken English to help you feel less lonely. People will do it. Humans are nice, gorgeous beings. Don’t be a fucking idiot. Don’t act like you got it. You ain’t got it, for the world is big, bold, beautiful, majestic and you are a piece of fine Diarrhoea grade shit.</p><p>I don’t want to be posh. I don’t want to appreciate wine. I don’t want to know the correct pronunciation of “Grand Prix”. I don’t know where the cheese in a Napoletina comes from. I know only one kind of cheese, Amul cheese and I love it. I don’t want to see the French rivera or the Italian country side. I love Ladakh and Ganga. I don’t know how to wear my socks correctly. No, I am not able to appreciate the flavour of a zucchini as much as I am able to make love to a Biryani. I don’t want to be well informed on global affairs. All the facade of being a “worldly man” can go fuck itself. I can’t tell the FED repo rate from a cutting chai if my life depended on it. I want to write code, I want to kayak, read some good books here and there, play music on my Boat speakers, meet fun beautiful human beings with a dark sense of humour and I want to be a bum. A lifelong bum. There are those who use the same yardstick to measure everyone without any respect for the inherent diversity of being, their yardstick determined mostly by what edge they have in life over others. There are those who always come from a place of judgement, not curiosity. Who think that their right is the only right, that all other rights are wrongs. Those whose fragile egos can not accept for a moment, that really, no one including themselves has a clue. Those who interpret our reality through patterns not our own but patterns of their own making, narrow patterns born out of their own malice and wilful ignorance. Well, go screw yourself.</p><p>Love will be returned with even more abundant love but the need for power masquerading as love will be shown the door. This is my life and I choose how to live it. Only I.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*89LZ_7KWcwYuKMTx" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*xBkW9QDLsnzmSTvK" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*mzLyrgEOgNUCKQlf" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*0NHQSAApL3MjtwJm" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*2pU3gAMY88UwV5vB" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yLUElv3Qki_i-nXCrvnp8Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZQ71fZK0B-wD_hWg_b-q4w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jqi1t0LehOcPUPAMn0vx3g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PylD64q7ivAar03IrwLfFg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x0rrAYG7_DgA32NziYNsgw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pEkQta2TqE8yHkPHHmQT0A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lx-favcn5ehneNyRCpAp2g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*Fg1eiHf-CfOiX5WPhDqS3A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*xjg3Lxt16Ye5A7RkFVz83Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*0_EIi3WexTQR5UWU9_Qktw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*wFZN-LTdU5ooYFMqLvRNDg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*bPGgLthBvw2pW_fNBn8iKA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*3l6UhqX1LXQT_BDErot2yw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wIRWR6xudnNfOWqzIu3pCw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*tQizf7sI8eHLkgh8KhYnHQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WOVZffNcpwnBR8QwKKVfEw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd06846692fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Only 137 ?]]></title>
            <link>https://medium.com/@aarshkshah1992/only-137-f191b0e189bd?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f191b0e189bd</guid>
            <category><![CDATA[short-story]]></category>
            <category><![CDATA[loneliness]]></category>
            <category><![CDATA[social-media]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Mon, 23 Jul 2018 14:39:37 GMT</pubDate>
            <atom:updated>2018-07-23T14:49:30.690Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*mSFccEuIzEgDpuVROry9AQ.png" /></figure><p>Only 137 likes, something was wrong. Every post before that had atleast 300. Maybe it was the hair. It was a bad hair day. Naah, the hair was right, her photo the day before had the same hair and it managed 277. The dress was different in that, light pink , and pink meant women for men and maybe that worked. But blue wasn’t bad too. So many blue’s had worked before. It was frustrating. Maybe she should have posted it on a weekend. Most likes were on weekends. Weekend posts were good, but the photo was really good, and weekend was still 4 days away. Maybe she should have pouted, but everyone was pouting and she wasn’t like them, plus pouts didn’t really work anymore. Classy was in. But the photo was classy, the elegant tight blue dress that her boyfriend had gifted her, the red purse that went perfectly with the blue dress, the piano in the background and the subtle smile that showed some hidden pain, it was perfectly classy.</p><p>She could easily get more likes if she was less stringent about who she allowed to follow her, but she was afraid of all the creeps there, who used the photos as porn, so she would check the photos of people who sent her requests to make sure they were not creeps. But what was the point in getting more likes from creeps, plus if she did, what would be the difference between her and Neha. Something was wrong. She didn’t post any many pictures as before, because other things were taking up time, and maybe that’s why the likes had gone down, maybe she needed to increase the frequency and make the photos a bit more revealing, not classy. But her cousins were also on it, god forbid if her mom found out about all the revealing photos.</p><p>Most photos of hers that were popular were group photos which got more likes as followers of the other girls in the group liked it too. She didn’t have a problem with those photos as long as the other girls were only as good looking or less good looking than her, because then she could safely assume that most of the likes were for her. But ever since she had moved to her new job, she had gotten into a new group with 3 girls who were really hot and since most of her party pics had them, she was sure that most likes weren’t directed at her, infact, she doubted, at times, that even likes by her followers were directed at them. The only group photos with the 3 hot girls she liked were the ones where the 2 really cool guys in her team were standing on either side of her and holding her, because then, people in her team and office assumed that she was good friends with them, which then made a lot of people jealous.</p><p>Maybe she should delete this photo. Photos with less likes really affected her reputation, and replying to the comments of the few people who commented on them made her feel like a loser, but if she didn’t comment, people would get offended and not comment or like in the future.She had deleted photos with less likes before, and people never really noticed, which did make her anxious sometimes, but it also made her anxious if people who had liked the photo asked her why she’d deleted them, as she would then have to make up some lie about a family member not liking it.</p><p>She should have used a better caption. ‘I am a falling star, I shine bright even as I die’ was good, there was romantic pain in it, it was short hence sophisticated, and sounded poetic without requiring much effort to read, but it lacked the authenticity of an envy evoking caption like ’The 4th party this month’ or the loneliness of Neha’s caption ‘Fighting in the dark alley called life’. It was becoming harder to come up with new captions. Maybe she needed to go back to googling for captions, but people generally found out that the caption had been googled and that didn’t give a classy image. Maybe she needed to stop putting up captions completely, some of her friends never put up captions, and that worked just fine.</p><p>“Hey girl, want to go out for dinner ? Long time, no see, free today ?”, a Whatsapp message poped up on her phone. It was Raahil, a college friend who’d just shifted to her city for a job. “No yaar, I’m busy and tired. Let’s try for next weekend”.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f191b0e189bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Immutable Collections are Functions]]></title>
            <link>https://medium.com/musings-on-functional-programming/scala-your-immutable-collections-are-functions-423d2e8603e?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/423d2e8603e</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[immutable]]></category>
            <category><![CDATA[computer-programming]]></category>
            <category><![CDATA[computer-science]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Sat, 28 Apr 2018 14:09:01 GMT</pubDate>
            <atom:updated>2018-04-28T19:15:05.219Z</atom:updated>
            <content:encoded><![CDATA[<p>If you look at the code for collections in the standard library, you’ll see that each collection inherits from some specific function type. By laws of subtyping, this means that a collection can be used wherever the function type it inherits from is required. Let’s take a look at each collection along with an example of how to use it as a function.</p><h4>Set</h4><p>The definition for Set in the standard library looks like:</p><pre><strong>trait </strong>Set[A] <strong>extends (A =&gt; Boolean)</strong><br>                <strong>with </strong>Iterable[A]<br>                <strong>with </strong>GenSet[A]<br>                <strong>with </strong>GenericSetTemplate[A, Set]<br>                <strong>with </strong>SetLike[A, Set[A]] {......</pre><p>(A =&gt; Boolean) is a shorthand for the Function1[A, Boolean] trait which is the type a function that takes a parameter of type A and returns a Boolean. Thus, Set[A] is also a Function1[A, Boolean]. This function version of Set returns true if the given element is in the Set and false otherwise.</p><p>So, instead of writing:</p><pre><strong>val </strong>blackListedIds = <em>Set</em>(<strong>&quot;ax123&quot;</strong>,....)<br><strong>val </strong>usersIds = <em>List</em>(<strong>&quot;abc123&quot;</strong>,...)</pre><pre>usersIds.filterNot(blackListedIds.contains(_))</pre><p>we can simply write:</p><pre><strong>val </strong>blackListedIds = <em>Set</em>(<strong>&quot;ax123&quot;</strong>,....)<br><strong>val </strong>usersIds = <em>List</em>(<strong>&quot;abc123&quot;</strong>,...)</pre><pre>usersIds.filterNot(blackListedIds)</pre><h4>Map</h4><p>The definition of the Maplike trait in the standard library looks like:</p><pre><strong>trait </strong>MapLike[K, +V, +This &lt;: MapLike[K, V, This] <br> <strong> extends PartialFunction[K, V]</strong><br>     <strong>with </strong>IterableLike[(K, V), This]....</pre><p>Since MapLike is a base trait of Map and extends a PartialFunction, it means that Map is also a partial function which takes a parameter of type K and returns a value of type V.</p><pre><strong>Partial Functions</strong></pre><pre>A PartialFunction[K,V] is a Function1[K,V] which is  not defined for all inputs of type K. A classic example would be the sqrt function which is only defined for non-negative integers. The &#39;isDefined&#39; method of PartialFunction tells us whether it is defined for a given input or not. Scaladoc explains this in detail:</pre><pre><strong>trait PartialFunction[-A, +B] extends (A =&gt; B)</strong> { self =&gt;<br>  <strong>import </strong>PartialFunction._</pre><pre>  <em>/** Checks if a value is contained in the function&#39;s domain.<br>   *<br>   *  </em><strong>@param  x   </strong><em>the value to test<br>   *  </em><strong>@return </strong>`&#39;&#39;&#39;<em>true</em>&#39;&#39;&#39;`<em>, iff </em>`<em>x</em>` <em>is in the domain of this function, </em>`&#39;&#39;&#39;<em>false</em>&#39;&#39;&#39;` <em>otherwise.<br>   */<br>  </em><strong>def isDefinedAt(x: A): Boolean</strong></pre><pre>The well written <a href="http://blog.bruchez.name/2011/10/scala-partial-functions-without-phd.html">Scala Partial Functions</a> blog post is a great read to grok Partial Functions in Scala in more detail.</pre><p>A Map[K, V] is a partial function because it is only defined for values of type K which are keys in our map. The implementation of the ‘<em>isDefinedAt</em>’ for MapLike too says the same:</p><pre><strong>def </strong>isDefinedAt(key: K) = contains(key)</pre><p>Thus, we can use a Map[K,V] wherever we need a Partial Function[K,V].</p><p>A good example of this is the <em>collect</em> method where we can pass a Map as a partial function:</p><pre><strong>type </strong>StudentId = String<br><strong>type </strong>Sport = String<br><strong>type </strong>Coach = String</pre><pre>// Some sports may not need a coach<br><strong>val </strong>coaches: Map[Sport, Coach] = <em>Map</em>(...)</pre><pre>// Not all students may be interested in a sport<strong><br>val </strong>studentInterests: Map[StudentId, Sport] = <em>Map</em>(...)</pre><pre><strong>def </strong>getCoachesToCall(students: List[StudentId]) =<br>  students.collect(studentInterests).collect(coaches)</pre><p>Pretty cool, don’t you think?</p><h4>Vector</h4><p>A Vector inherits from a Sequence and if you look at the definition of the Sequence trait in the standard library, you’ll see:</p><pre><em>/** A base trait for sequences.<br> *  $seqInfo<br> */<br></em><strong>trait </strong>Seq[+A] <strong>extends </strong>PartialFunction[Int, A]</pre><p>Thus, a Vector[A] is also a PartialFunction[Int, A]. This is because a Vector(i) function call to access the ith element of the Vector is defined only for those values of i which are greater than -1 and less than the length of the Vector.</p><pre><strong>def </strong>isDefinedAt(index: Int) = index &gt;= 0 &amp;&amp; index &lt; length</pre><p>A great example of using Vectors as partial functions can be found here:</p><p><a href="https://stackoverflow.com/questions/20004127/vector-access-with-potentially-undefined-index">Vector access with potentially undefined index</a></p><p>We can also use a Vector as a partial function in <em>collect</em>, just like we did with Map:</p><pre><strong>val </strong>indices = <em>List</em>(1,10,4,2,100)<br><strong>val </strong>vector = <em>Vector</em>(2,100,20,4,7,6)</pre><pre><strong>val </strong>output = indices collect(vector)<br>&gt; output: List[Int] = List(100, 7, 20)</pre><p>We treat each value in indices as an index, and collect all values vector(index) such that the vector partial function is defined for index i.e. the index is not out of bounds for the vector.</p><h4>List</h4><p>Since List is also a Sequence, the idea of List as a function is same as that of Vector. However, the use of Lists as partial functions should be avoided as Lists aren’t really meant for random access. If random access is what you are after, Vectors are the way to go.</p><p><strong>Optional Reading: Modelling the Set of Natural Numbers as a function</strong></p><p>The Week 2 exercise of Martin Odersky’s Coursera course on Scala asked us to implement the Set of all natural numbers in terms of pure functions without using any persistence. I encourage you to go through the exercise as it really drives the point home. The solution I wrote can be found at: <a href="https://github.com/aarshkshah1992/Coursera-Functional-Programming-Principles-in-Scala/blob/master/Week%202%20funsets/src/main/scala/funsets/FunSets.scala">Functional Sets</a></p><p>Hope this was a good read! Please do leave your feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=423d2e8603e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/musings-on-functional-programming/scala-your-immutable-collections-are-functions-423d2e8603e">Your Immutable Collections are Functions</a> was originally published in <a href="https://medium.com/musings-on-functional-programming">Musings on Scala and Functional Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Type Classes in Scala]]></title>
            <link>https://medium.com/musings-on-functional-programming/type-classes-in-scala-1e6dc1a52e8e?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e6dc1a52e8e</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Sat, 28 Apr 2018 14:06:36 GMT</pubDate>
            <atom:updated>2018-04-29T08:59:24.671Z</atom:updated>
            <content:encoded><![CDATA[<p>Type classes allow us to push the limits of extensibility of our types. It is an elegant way of adding new behaviours to existing types without changing the implementation of the type itself. Let’s dive straight to the code. We will use the Scala REPL for all our examples</p><h4>A Simple Example: Finding the Maximum</h4><p>Let’s say we have the following code to find the maximum in a list of Integers :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eaeb63991e93f667decdf3a90baf6c13/href">https://medium.com/media/eaeb63991e93f667decdf3a90baf6c13/href</a></iframe><p>Suppose we are writing an application which manages the admin work for an University. We are tasked with maintaining various statistics for each student like his SAT score and GPA. We also have to maintain the number of papers each professor has published and his years of teaching experience. Student &amp; Prof stats are represented as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd20f00f1791a3f88c3acfc686cc110e/href">https://medium.com/media/fd20f00f1791a3f88c3acfc686cc110e/href</a></iframe><p>Given a List of StudentStats, how would we find the student with the highest SAT score? We could of course copy and modify the code we used for a List of Integers and come up with the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8e203cf5c820ac195ca6ecc18827504/href">https://medium.com/media/b8e203cf5c820ac195ca6ecc18827504/href</a></iframe><p>How about finding the professor with the most experience?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60691c75e9f0ed4f8f19a464be279675/href">https://medium.com/media/60691c75e9f0ed4f8f19a464be279675/href</a></iframe><p>How about finding the Student with the highest GPA?</p><p>You get the idea. But, we are duplicating code and there is a lot of repetition. <em>Repetition is usually the first sign of an abstraction waiting to be discovered.</em></p><h4>A TypeClass to define Ordering</h4><p>The only distinct feature across all these functions is the comparison between the corresponding types. If we can define an Ordering on these types and pass it along to our ‘findMax’ function, we can re-use the same findMax function across multiple types.</p><p>Let’s define a CustomOrdering trait and make sure there are implementations for ‘each ordering’ that we want to use. We can have multiple ‘orderings’ for the same type. Our entire code then looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03f51f2037ca4fed65d1d107e621fbc8/href">https://medium.com/media/03f51f2037ca4fed65d1d107e621fbc8/href</a></iframe><p>A generic findMax would then look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97ab3177064ea07f9c405f43fdc761ff/href">https://medium.com/media/97ab3177064ea07f9c405f43fdc761ff/href</a></iframe><p>So far, so good. But there is a problem here. We need to explicitly pass the ordering we want to use. It would be great if the ordering was passed <strong><em>implicitly</em></strong> and the caller wouldn’t have to worry about passing a specific ordering to findMax.</p><p>Here is where Scala’s implicits are of great help. We can pass CustomOrdering as an implicit argument to findMax and make sure that an ordering is in implicit scope when findMax is called.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a65d7c1dfa6f67c23e8fab87ef147e59/href">https://medium.com/media/a65d7c1dfa6f67c23e8fab87ef147e59/href</a></iframe><p>The call would then look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed0d532e6833662183eac761c28c099b/href">https://medium.com/media/ed0d532e6833662183eac761c28c099b/href</a></iframe><p><strong>A brief note on implicits &amp; imports</strong></p><ul><li>If we hadn’t imported <em>maxByScore</em> in the code above, the Scala compiler would look into the StudentStats companion object by default, but since we have defined two implicit orderings there, it wouldn’t know which one to use.</li><li>In cases where only one Ordering makes sense (Integers for example), we can define the implicit in the companion object of the type and the Scala compiler would pick it up without us having to import it.</li><li>The Scala compiler will also look in the companion object of the CustomOrdering trait by default, which means that we can also define an implicit ordering there and it will get picked up.</li></ul><p><strong>So what is the Type Class Pattern you ask?</strong></p><p>Well, we just implemented it. Surprised?</p><p>1.) We defined a type class CustomOrdering</p><p>2.) We made StudentStats and ProfessorStats <em>members of the type class CustomOrdering</em> by making sure that values of type CustomOrdering[StudentStats] and CustomOrdering[ProfessorStats] were implicitly available when they were required .</p><p><em>So, any type T can be made a member of a type class TC[_] by making sure that a value of type TC[T] is implicitly available when it is required.</em></p><p>3.) Finally, we defined a method <em>findMax</em> that takes an implicit type class implementation.</p><p>Note that this is a bit different from sub-typing that we are used to in Object Oriented languages. The type T or rather the implementation of type T dosen’t even need to know that it is a member of type class TC. Any type T can be made a member of TC by defining an implicit value of type TC[T]. Thus, we don’t even need access to the source code of T.</p><p>Type classes are really useful when we want to extend the behaviour of existing types without modifying them. They even allows us to add new behaviours to third party libraries whose source code we do not have access to.</p><p>The CustomOrdering[T] type class we defined is already defined in the Scala standard library and is called Ordering[T]. The standard library already has implementations of Ordering[T] for standard types like Int, Double, String etc.</p><h4>Context Bounds: Syntactic Sugar for Removing Boiler Plate</h4><p>The following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/643369be00dffba4009116a99287df6b/href">https://medium.com/media/643369be00dffba4009116a99287df6b/href</a></iframe><p>can also be written as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef8b6ef8e4c035a1acfd924288a87ebe/href">https://medium.com/media/ef8b6ef8e4c035a1acfd924288a87ebe/href</a></iframe><p>The syntax [T:CustomOrdering] is called a context bound<strong>.</strong> It tells the compiler that an implicit value of type CustomOrdering[T] will be in scope when findMax is called.</p><p>In order to access this value, we need to write implicitly[CustomOrdering[T]]. It fetches an implicit value of type CustomOrdering[T] from the current scope. The definition of implicitly should tell us how it works:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fae3634fd6b9eee3dcbbee7171219edc/href">https://medium.com/media/fae3634fd6b9eee3dcbbee7171219edc/href</a></iframe><p>We can even define multiple context bounds:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2b24ee0f310711a34071f71e80ca19d/href">https://medium.com/media/a2b24ee0f310711a34071f71e80ca19d/href</a></iframe><p>Hope this was a good read. Do leave a comment with your suggestions :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e6dc1a52e8e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/musings-on-functional-programming/type-classes-in-scala-1e6dc1a52e8e">Type Classes in Scala</a> was originally published in <a href="https://medium.com/musings-on-functional-programming">Musings on Scala and Functional Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scala: Optimizing expensive functions with Memoization]]></title>
            <link>https://medium.com/musings-on-functional-programming/scala-optimizing-expensive-functions-with-memoization-c05b781ae826?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c05b781ae826</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[memoization]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Sat, 28 Apr 2018 13:55:06 GMT</pubDate>
            <atom:updated>2018-04-28T13:55:06.020Z</atom:updated>
            <content:encoded><![CDATA[<p>Memoization is an optimization technique of caching the output of an expensive function for a particular input and then returning the cached result if the function is called again with the same input parameters. Think of it as a lazy loading cache where the key is the set of input parameters and the value is the output of the function call. This technique is especially well suited to the world of functional programming since pure functions always evaluate to the same output for the same input. Let’s see how we can memoize functions. We will use the Scala REPL for all examples.</p><h4>Checking if a given number is a prime</h4><p>A function to determine whether a given number is prime would look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a246363c1d5ebb7d0b651281db0a3401/href">https://medium.com/media/a246363c1d5ebb7d0b651281db0a3401/href</a></iframe><p>Checking whether a number is prime or not is an expensive operation. We want to do it only once for a given number by caching the output and returning the cached output if we are asked to check the primality of the same number again. We obviously want to do it in a way that is invisible to the caller. Here’s an implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8796ec08a20a1048f8d0e29b0cec419/href">https://medium.com/media/c8796ec08a20a1048f8d0e29b0cec419/href</a></iframe><p>For reference, the implementation of <em>getOrElse</em> on Map in the standard library looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c7d12b651dee6d6477d0ef772065504/href">https://medium.com/media/1c7d12b651dee6d6477d0ef772065504/href</a></iframe><p>Note that the ‘<em>default</em>’ expression is evaluated only if we get a cache miss since it is a by-name param.</p><p>Let’s break down what we did into understandable steps:</p><ul><li><em>memoizedIsPrime </em>contains <em>isPrime</em> as a nested function.</li><li>When we call <em>memoizedIsPrime, </em>it first initializes an empty cache. It then returns a function that forms a closure over the cache, takes an integer as an input and calls <em>getOrElse</em> on the cache. If there is a cache hit, <em>getOrElse</em>simply returns the cached value. If there is a cache miss, it evaluates the expression we pass to it, which basically calls isPrime for the input, updates the cache with the primality of the input and returns the cached value.</li><li>The mutability of the cache is not visible outside the <em>memoizedIsPrime </em>function since the cache is owned by and can be updated only by the <em>memoizedIsPrime function.</em></li><li>The line <em>val isPrime = memoizedIsPrime</em> initializes <em>isPrime</em> with the function returned by <em>memoizedIsPrime</em>. Note that <em>isPrime</em> is a val and not a def since we want to call <em>memoizedIsPrime</em> only once as calling it multiple times will result into a new instance of the cache every time.</li></ul><h4>A generic Memoization API: Memoizing any multi-arg function</h4><p>Let’s say we want to extend the functions we wrote above so that we can memoize any multi-arg function. It can done as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4fd9ed3b6f923eb9c635379ca0c567a2/href">https://medium.com/media/4fd9ed3b6f923eb9c635379ca0c567a2/href</a></iframe><ul><li>We have memoized the <em>add</em> &amp; <em>concat3Strings </em>functions in <em>memoizedAdd </em>&amp; <em>memoizedConcat </em>respectively.</li><li>The <em>add _ tupled</em> syntax is to convert add into a function that takes a tuple of integers as an input rather than taking two integers . This is because the function that we pass to <em>memoizeFnc</em> can take only one type K in it’s input.</li></ul><h4>Scalaz Memo: A powerful library for Memoization</h4><p>An elegant &amp; more powerful implementation of a memoization API can be found in the scalaz.Memo library. A good tutorial for Memo is<a href="http://eed3si9n.com/learning-scalaz/Memo.html"> Learning Scalaz Memo</a>. Here’s a simple example of Memo that uses an immutable Hash Map for the cache:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/141a132c193b2d7e557f6e0e6237a621/href">https://medium.com/media/141a132c193b2d7e557f6e0e6237a621/href</a></iframe><p>I encourage you to have a look at it’s implementation as it offers multiple implementations of memoization by using different data structures for caching.</p><p>Please feel free to leave your suggestions or questions in the comments section :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c05b781ae826" width="1" height="1" alt=""><hr><p><a href="https://medium.com/musings-on-functional-programming/scala-optimizing-expensive-functions-with-memoization-c05b781ae826">Scala: Optimizing expensive functions with Memoization</a> was originally published in <a href="https://medium.com/musings-on-functional-programming">Musings on Scala and Functional Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Error accumulation with collection of Futures]]></title>
            <link>https://medium.com/musings-on-functional-programming/error-accumulation-with-collection-of-futures-82fb4da47466?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/82fb4da47466</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[scala]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Sat, 28 Apr 2018 13:37:18 GMT</pubDate>
            <atom:updated>2018-04-28T13:37:18.288Z</atom:updated>
            <content:encoded><![CDATA[<p>Of late, I’ve been dealing with problems related to accumulating errors from multiple futures. Combinators like <em>map</em>, <em>flatmap</em>, <em>sequence</em> and <em>traverse</em> have a fail-fast behaviour. While composing or sequencing multiple Futures, they return the first failed Future they encounter. However, sometimes, we want to find out what else could have gone wrong. I could describe the problem in more detail, but as Linus Torvalds once said “Talk is cheap, show me the code”. Let’s get our hands dirty and write some code. We will use the Scala REPL for all examples. Please use Scala 2.12 to run the examples.</p><p><em>Note: We will ignore imports and Execution Context in all examples for the sake of simplicity.</em></p><h4>A motivating example</h4><p>Given a list of strings representing integers, the code to find it’s sum would look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c8d28736a9647da3431c37dc14e3f82/href">https://medium.com/media/5c8d28736a9647da3431c37dc14e3f82/href</a></iframe><p>But, if a given string is not an integer, ‘<em>toInt</em>’ throws an exception:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/454f42ff8c80ce60817354618ac6743f/href">https://medium.com/media/454f42ff8c80ce60817354618ac6743f/href</a></iframe><p>If we want to concurrently convert each string to an integer and then find the sum, we first wrap the call to <em>toInt</em> in a Future. We then get a list of futures, use <em>Future.sequence</em> to get a future over a list of integers and <em>map</em> over the future to find the sum of the list:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef5e035d03e96e2e4f8fca8ac929bdb0/href">https://medium.com/media/ef5e035d03e96e2e4f8fca8ac929bdb0/href</a></iframe><p>A more general way to do this is to use <em>Future.traverse</em> as traverse basically represents a map followed by a sequence :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6d6c39952e4beb5140a581c592a53dd/href">https://medium.com/media/c6d6c39952e4beb5140a581c592a53dd/href</a></iframe><h4>Fail-fast behaviour of Futures</h4><p>But, there’s a problem with with what we’ve done. What if one of the strings is not an integer?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8cf978795a420eca78c3a047cf22fc26/href">https://medium.com/media/8cf978795a420eca78c3a047cf22fc26/href</a></iframe><p>The futSum future is failed with an exception and since we use Await on a failed future, the exception is thrown. This is as expected. Things began to get more interesting once we have multiple failures. What happens if there is more than one string that can’t be converted to an integer?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d83cc5545482d1b6bc779ea8c6cde25b/href">https://medium.com/media/d83cc5545482d1b6bc779ea8c6cde25b/href</a></iframe><p>We get the same exception as before! It only tells us that the string ‘failure1’ can’t be converted to an integer. It tells us nothing about the fact that ‘failure2’ and ‘failure3’ too would have failed. Why is that? The answer lies in the fail fast behaviour of Future composition, or more specifically, in the implementation of <em>Future.traverse</em>.</p><h4>Why is traverse fail-fast ?</h4><p>Here’s the implementation of <em>traverse</em> from the standard library that I’ve modified slightly to make it more readable:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc55a2be55ed420d7601d4cd4290fc14/href">https://medium.com/media/bc55a2be55ed420d7601d4cd4290fc14/href</a></iframe><p>The zipWith function which combines two futures into a single future is the key to understanding the fail fast behaviour. It’s documentation and implementation in the Future library looks like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f819d4f126e8054aed1078718613420d/href">https://medium.com/media/f819d4f126e8054aed1078718613420d/href</a></iframe><p>As we can see, <em>zipWith</em> uses the well known fail-fast <em>flatMap</em> and <em>map</em>combinators under the hood. The documentation for both <em>map</em> and <em>flatMap</em>clearly states that if the outer future fails with an exception, the resultant future will be failed with the same exception:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74097aed16ab5d910990e5b08a15c7a2/href">https://medium.com/media/74097aed16ab5d910990e5b08a15c7a2/href</a></iframe><p>Thus, when we use <em>zipWith</em>, the resultant future is failed with the first failed future that is encountered while composing ‘this’ and ‘that’ Future. The documentation too states that in no uncertain terms. The implication of this for Future.traverse is that when folding a list of futures, the resultant future will be failed with the exception of the first future that fails. How do we solve this? How do we accumulate all the exceptions?</p><h4>First attempt at error accumulation: map, recover, Try and Either</h4><ul><li>We lift a Future[T] to a Try[Future[T]] so that all futures are successful and we do not have to deal with failed futures. <em>Future.map</em> and <em>Future.recover</em> are our friends for this.</li><li>If a Future is successful, it’s type will be Future[Success[T]] and it fails, it’s type will be Future[Failure[Throwable]]. In either case, our Future will always be successful.</li><li>Once we have lifted all our Futures using Try, our error accumulation semantics are as follows:</li><li>If all the lifted Futures contain a Success, we return the result we want, the sum of all integers in our case.</li><li>If even lifted Future contains a Failure, we accumulate the exceptions from all Futures and return the List of exceptions.</li><li>The best type to model both the above behaviours is an Either[List[Throwable], Int]. We will return either the sum or the list of all exceptions.</li></ul><p>Putting all this together, we get the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/02434248af25d2b8f9e4e8086dbb1a2c/href">https://medium.com/media/02434248af25d2b8f9e4e8086dbb1a2c/href</a></iframe><p>Another way to do this is to <em>fold</em> the list of lifted Futures and use pattern matching to implement the idea of building the result if all Futures contain a success or return all the exceptions otherwise:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b26367fa6718fab9aee2e4b13274928f/href">https://medium.com/media/b26367fa6718fab9aee2e4b13274928f/href</a></iframe><p>We have successfully collected all exceptions from a collection of Futures. Is there a more general way/type to do this so that we can get rid of some of the heavy lifting we need to do? After all, this idea of accumulating all errors if even a single expression fails and returning a success value only if all expressions are successful seems like a pretty common use case.</p><h4>Scalaz ValidationNel : Type with error accumulation semantics</h4><p>The Scalaz library comes with a type ValidationNel that is meant to do just this: error accumulation if even a single expression fails, return a success otherwise. There are some great posts that explain this type in detail:</p><p>1.) <a href="http://1.) http://eed3si9n.com/learning-scalaz/Validation.html">Learning ScalaZ Validation</a></p><p>2.) <a href="https://www.47deg.com/blog/fp-for-the-average-joe-part-1-scalaz-validation/">Scalaz Error accumulation tutorial by 47 degrees</a></p><p>Once you’ve gone through these posts, you’ll already get a feel for how we can accumulate errors from multiple futures using ValidationNel. Here’s the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40bcb5e34acedce3a2d7b1c1d19df144/href">https://medium.com/media/40bcb5e34acedce3a2d7b1c1d19df144/href</a></iframe><p>The <em>+++</em> operator is very interesting. Even though ValidationNel is a parameterized type:</p><p><strong>sealed abstract class </strong>Validation[+E, +A]<br><strong>type </strong>ValidationNel[E, +X] = Validation[NonEmptyList[E], X]</p><p>We are still able to accumulate the exceptions or add the Integers without explicitly supplying a function to do that. How doe that work? The answer lies in the magic of type classes and semi-groups. However, that’s out of scope for this article. I leave it for you to discover. Hope you enjoy your further journey ! :)</p><p>Please do leave a comment with your questions/suggestions and feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82fb4da47466" width="1" height="1" alt=""><hr><p><a href="https://medium.com/musings-on-functional-programming/error-accumulation-with-collection-of-futures-82fb4da47466">Error accumulation with collection of Futures</a> was originally published in <a href="https://medium.com/musings-on-functional-programming">Musings on Scala and Functional Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Dark Cloud]]></title>
            <link>https://medium.com/@aarshkshah1992/dark-clouds-30e9746f34a8?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/30e9746f34a8</guid>
            <category><![CDATA[depression]]></category>
            <category><![CDATA[suicide]]></category>
            <category><![CDATA[mental-health]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Sat, 10 Feb 2018 07:12:46 GMT</pubDate>
            <atom:updated>2018-02-15T10:42:37.873Z</atom:updated>
            <content:encoded><![CDATA[<p>A dark cloud, parched permanently on your soul. Every dwelling of joy and hope that resides within the depths of your fighting heart ,washed away by the torrential ferocity of that cloud. It kills you, one drop at a time, gradually breaking your resolve to stay afloat, till you give up and choose to drown . You know drowning is scary, but you can’t keep fighting anymore. It is an escape from that cloud, a permanent solution.</p><p>According to a report by the WHO, about five crore people in India suffer from depression. That’s 5 percent of our population.The total number of people living in depression increased by 20 percent between 2005 and 2015. 1 out of every 5 corporate employee is suffering from depression. 135000 people committed suicide in 2012 in India. That’s 371 suicides every day.Suicide is the second leading cause of death in the 18–29 group.</p><p>And yet, inspite of this widespread epidemic of depression, the number of people seeking treatment for it is abysmal. People refuse to go to a psychiatrist even when they’re sure something’s wrong with their mental health. Why should they ? Society demonises them as as ‘mentally disturbed’ or a ‘paagal’, depriving them of a life of dignity. The social stigma associated with being depressed in India forces the family of a patient to keep it a hush-hush matter . Imagine getting your son or daughter married after it’s public knowledge that they’re suffering from depression.</p><p>The problem is compounded by this age of social media and personal achievement we are living in. Every fibre of our being is devoted to projecting a perfect image on social media, banging our drums about rockets being launched into space and buying the latest car. Getting into a good university, finishing a race, travelling a Paris, falling in love , everything needs to be announced to the world. We always need to be happy and successful, for our existence is futile otherwise. Can you imagine what this does to the mental health of those misfortuned souls, who can not afford any of this, either because they lack the material wealth or are devoured by the clouds of depression ? But of course, we, you and I , don’t care because we are busy in our own dance of seeking attention.</p><p>The other problem is our refusal to look at depression as a disease and blame it on the inaction of the person suffering from it. Imagine telling someone suffering from jaundice that ‘It’s all in your head’, ‘You only think you have jaundice’, ‘’focusing your mind on work and other activities will cure your jaundice’, ’Masjid mein maulvi se jhaadu marvaane se theek ho jaayega’. Sounds unbelievable , right ? And yet, these are the exact same words and phrases that are repeated to a depressed person day in and day out, shoved into their ears till they become convinced it’s all their fault. What do you think it does to them ?</p><p>The thought that material wealth, fame , success are great antidotes for depression is also laughable, given the overwhelming evidence against it. Ernest Heminway, David Foster Wallace, Slvia Plath, Chester Bennington, Robin Williams,Guru Dutt, Nafisa Joseph, Kurt Kobain, the list goes on and on. People who were at the pinnacle of their career,actors, businessmen, writers, nobel prize winners, billionaires, depression doesn&#39;t discriminate. It strikes anyone and everyone,your bank account or number of fans is immaterial to it.</p><p>Have you been engulfed by the dark cloud ? To those suffering from depression , I say that “The fables and fairy tales of all ages, recited and passed down to generations by wise old men tell us that demons can be slayed.I will never be able to understand what you feel and go through, but we acknowledge these personal demons, and hope that you never lose hope, for the death of hope is the death of all”..</p><p>We need more sympathy and empathy as individuals, as a society. Let’s not be afraid of talking about it if we are suffering from it, of talking to those suffering from it. Let’s not ostracize people suffering from it. Let it not be a social taboo. You and I together, can save 371 people everyday,but, only if we work together.</p><p>To explain , in no easy words, why people suffering from this demon , choose to end their lives, I conclude with a quote by a great writer who the world lost to this demon long ago :-</p><p><em>“The so-called ‘psychotically depressed’ person who tries to kill herself doesn’t do so because death seems suddenly appealing. The person in whom Its invisible agony reaches a certain unendurable level will kill herself the same way a trapped person will eventually jump from the window of a burning high-rise. Make no mistake about people who leap from burning windows. Their terror of falling from a great height is still just as great as it would be for you or me standing speculatively at the same window just checking out the view; i.e. the fear of falling remains a constant. The variable here is the other terror, the fire’s flames: when the flames get close enough, falling to death becomes the slightly less terrible of two terrors. It’s not desiring the fall; it’s terror of the flames. And yet nobody down on the sidewalk, looking up and yelling ‘Don’t!’ and ‘Hang on!’, can understand the jump. Not really. You’d have to have personally been trapped and felt flames to really understand a terror way beyond falling”<br> — David Foster Wallace (1962 -2008)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30e9746f34a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Better Place]]></title>
            <link>https://medium.com/@aarshkshah1992/a-better-place-664503d3cf92?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/664503d3cf92</guid>
            <category><![CDATA[dreams]]></category>
            <category><![CDATA[love]]></category>
            <category><![CDATA[autobiographical]]></category>
            <category><![CDATA[hopes-and-dreams]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Sun, 04 Feb 2018 19:46:36 GMT</pubDate>
            <atom:updated>2018-02-13T07:25:34.724Z</atom:updated>
            <content:encoded><![CDATA[<p>I was 21 when I came to Mumbai, it was my first paid internship. A heart full of dreams , ambitions dancing on my palms, immense love for life, immense lust for life. It was the city of dreams after all. I was here to live my dreams, escape my current reality. I thought I could take on anyone and everyone, that the raging poetry of my imagination could easily engulf the mundanity of life.</p><p>It took me a while to realise that there were a million Aarsh Shah’s exchanging their dreams for reality in this ruthless city.</p><p>It was a city where a family of five spent their entire life in one room.The mom woke up at 6 AM everyday to make tiffins for her 20 demaning customers, tiffins which were delivered by her older son in tormenting heat and unbearable traffic. Her daughter spent her entire day getting pushed around in inhumane and conjested trains, barely getting 5 hours to sleep , after a 12 hours job and four hour commute. All this, to afford the rent and the medical bills of the father, a 55 year old blood pressure and diabetes patient, who couldn’t find a well paying job because a lack of formal education</p><p>Hoping, praying, pleading , never giving up, never giving up.</p><p>The rents were painfully astronomical, 25 thousand for a 1-BHK, 40 for two. What about 3 ? Well, I didn’t dare ask. They told me that the stipend would get credited at the end of month. Since I came from a poor family, this meant that I didn’t even have the money to pay the rent for most of these houses, forget about the brokerage and deposit. With no other option in sight, I began living in a small ‘room’(if you can call it that) in a local chawl next to the station. The rent was a beautiful 3000 a month. The water in that chawl was extremely British, for it was very punctual. It arrived at 6 AM sharp everyday, and departed at 7. I would wake up at 6 clock every morning to fill the buckets with water for failing to do so would mean a day without water. The toilet on my floor was shared among all the 12 occupants . Among other things, this meant that the timeliness of my bowel movements had to compete with that of Dhanji bhai living next to me. And let me tell you, he was an extremely tough competitor, which meant that the office became the main stage for my performance. At night, while talking to mom, she would always unfailingly ask me if I was okay, and I, being the good fiction writer that I was, always said yes. I was really unhappy.</p><p><strong>I wanted to shift to a ‘better place’.</strong></p><p>The day the stipend arrived , a cool 30000 bucks,was a day of joy. I called up every broker in Malad, pleading with them to show me a half decent place that didn’t require a deposit. Finally, a broker showed me a PG very near to my office. It was a 3 BHK, shared by 13 people. 4 in the hall, and 3 in each room. It had three bathrooms, which meant that I had to share ‘my’ bathroom with only 4 other people. I had progressed in life.</p><p>I shared my room with two decent blokes. One was a struggling actor. He played the role of dead body number 3 in CID episode number 512. He was extremely proud of it.He dreamt of being dead body number 1 some day.</p><p>Somewhere among those 12 amazing people,each of them trying to make it in life, I found myself. For I learnt that everybody has dreams .Everybody suffers. I wasn’t the only one. The magic of a multitude far surpasses the loneliness of a limitless ego, for you see yourself in everyone. These enchanting mirrors of humanity, these imperfect broken souls,all dancing to the maddening tunes of life.</p><p>However, sharing my room with two other people was a frustrating experience.</p><p><strong>I wanted to shift to a ‘better place’.</strong></p><p>As time passed, 1 tick at a time, things began changing for me. I converted my internship to a full time job.My salary went beyond my wildest dreams and I shifted to a fully furnised 2-BHK and began sharing a room with my best friend from college. It was a great time. We drank together, sang together, fell in love together, dreamt together, failed together. But..something was missing in life. I was sharing a room and everybody told me that you ought to have your ‘personal space’.Somewhere, deep inside, even I felt that it would be great to have a whole room to myself, without having to talk to the same person every night ,playing whatever music I wanted , at whatever volume I wanted. <br> <br> <strong>I really wanted to shift to a ‘better place’.</strong></p><p>Now that I have my own room, I dream of buying my own house in Bandra someday. I am bored with this room in Malad. I want to live in an area with some nice cafes, a great sea side jogging path, running alongside people who direct CID’s rather than become dead bodies .</p><p><strong>I wanted to shift to a ‘better place’.</strong></p><p>You see guys, greed has no limits.The luxury trap is a one way street , where we are only allowed to go up and before we know it, we are enslaved to material comforts, sacrificing a lot of other important things in life for it. The only good place is right here, right now, chasing our dreams, suffering , falling in love and making friends and foes.</p><p><strong>There is no ‘better place’.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=664503d3cf92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lost Cappuccinos]]></title>
            <link>https://medium.com/@aarshkshah1992/lost-cappuccinos-65a041adeedf?source=rss-54aaaf1913a------2</link>
            <guid isPermaLink="false">https://medium.com/p/65a041adeedf</guid>
            <category><![CDATA[short-story]]></category>
            <category><![CDATA[depression]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[love]]></category>
            <category><![CDATA[poetry]]></category>
            <dc:creator><![CDATA[Aarsh Shah]]></dc:creator>
            <pubDate>Mon, 20 Feb 2017 15:18:36 GMT</pubDate>
            <atom:updated>2017-02-23T04:41:38.642Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HkwcHplwjWqkYWx7.jpg" /></figure><p>Rahul thought cigarettes made him look cool. He adorned them on his lips like ornaments, whirling circles of smoke at the world, often promising himself he’d quit next week.</p><p>‘You always taste of nicotine. I am weird. I’m supposed to love cherries , strawberries and wine, but this nicotine taste, it makes me want to keep kissing you again and again,’ she’d say, before stealing one more kiss.</p><p>‘Why are you supposed to love strawberries and wine ?’</p><p>‘Because I’m 23, beautiful, poor and a writer.’</p><p>They loved cappuccinos. It wasn’t the coffee beans, it were the conversations. Over cups and cups, they’d talk of Immortality, Rebirth, God, Bradbury, Dickens, Marquez, Dylan and Nancy Sinatra. She’d left him long ago, the cappuccinos now lost, her kisses stored in his poetic memory and his soul, broken.</p><p>He used to play at cheap bars, trying to make ends meet in Mumbai, his audience unaware of his presence, indifferent to his chords. He’d sing song after song, play melody after melody, reminding himself that The Beatles played for two thousand days to drunk audiences all over Europe before anybody gave a fuck about them. He’d do four gigs a day, in the deepest and darkest corners of an unforgiving city, making just about enough to pay the bills and smoke the cigarettes.</p><p>Rahul, 24, thus met Sunaina, 23 when he was trying to learn life.</p><p>He’d asked for a female audience member to join him on stage for a song. A girl raised her hand, he selected her, for she was breathtakingly beautiful.</p><p>‘So, ma’am, what song do you want me to play?’</p><p>‘It’s Sunaina, and I want to play a song I’ve written, will that do ?’</p><p>‘Ah, a writer, of course, we must entertain you, for you are a dying breed. Let’s do one thing, start singing. I’ll play the guitar once I have the melody in my mind.’</p><p>The song was still so strong in his memory that he could effortlessly sing it verbatim.</p><p>Lost stars, broken souls,<br>We need the light of the night,<br>A wavering mind, a fickle heart, <br>Not good for life, given up without a fight</p><p>It works out in the end,<br>Better than your fears,<br>Worse than your hopes,<br>Trod along, wipe your tears</p><p>Come love me O Darling,<br>Hate me, kiss me,<br>Silence my tormenting demons<br>Let’s run away, mad are we</p><p>Poor is life, <br>Harsh the winter,<br>Burn the bedsheets,<br>Light, warmth, you and shiver</p><p>Dance, romance, words and silence,<br>I’ll shine, burn and fade,<br>Whisky, coffee, cigarettes and poems,<br>Bad vices, muddy waters, together we wade</p><p>Dead fishes in beautiful oceans,<br>The rose and it’s thorn,<br>Death in paradise<br>For you I was born</p><p>He didn’t understand then why she’d called herself a Lost Star. 4 years, 4000 kisses, 1 million conversations and 1 heartbreak later, he knew.</p><p>They’d sit on his couch , she’d write a song and he’d play it . She wrote, he composed, they sang. She had a gift for words, it far outclassed his gift for sounds, not always could he play what she wrote, for the lyrics sometimes demanded far better music than he could make.</p><p>She was depressed, didn’t know why. She’d cry for hours lying in his lap. He’d stay silent, as he’d been instructed long ago and wait for her tears to dry up, before he’d tell her how much he loved her, even with her fears and devils. Once, when he’d asked her to explain depression, she’d said ‘Imagine jumping from a building with infinite floors. You are constantly under the fear of death, of losing everyone you love and everything else ceases to matter. But it never gets over, it goes on and on and on. You just want death to come silence those fears.’</p><p>He didn’t know what to say. He’d stared silently at her unknown face, lighting one more cigarette. Sometimes, he wondered if she’d left him for his lack of words.</p><p>‘There are like six billion of us right. All of us wandering aimlessly, trying to find meaning. Why should I be restricted to just one person ? Why should the society dictate that I, Sunaina Bajaj, can make love to only one person my entire life, even if I’ve fallen out of love long ago ? My body, as much as my life, belongs to me and I can choose to share it with whoever I want, whenever I want and however I want,’ she’d said when he’d asked her for her thoughts on marriage. He’d often fantasized about spending his life with her. It would be a gift, torment and bliss, pink and purple. After that conversation, he got rid of his fantasies, knowing only too well how it was going to play out.</p><p>‘I’m not sure about Dylan, never will be . His voice is all rust and stardust, his poetry vague, his ego the size of mountains, his intentions holier than thou and his guitar too easy. The world goes gaga over his vague lyrics for they can mutate them to suit their ideas, who doesn’t love the freedom to interpret. But, as you grow older, ambiguity loses it’s charm, definite and real become the new love, for we give up on trying to find meaning and answers.</p><p>‘I loved him in my teenage but now that I’m older, I’ve moved on. Moving on isn’t easy Rahul, as you will know some day, but it happens like death, painfully, gradually and then all at once. It’s funny, we as a species dream of a peaceful life after death, exchanging favours with God so that he puts us in a place better than where we are now.</p><p>‘We don’t remember that there are far more dead people than there are alive, and God can only have so much space to accommodate his well wishers. I’m sure post death world is crowded, noisy and filthy, hence this innate fear of death. I want to be immortal by never dying, not by living in people’s memories. Memories are fickle, they change, manipulate and get manipulated. Plus, you’ll always remember me no? That is enough. You are enough.’</p><p>They were sipping wine on his terrace, gazing at a sky devoid of stars. He’d lighted a few candles and some Dylan was playing in the background.</p><p>She was lying in his lap. It’d always been that way, she in his lap. Never he in hers. He’d asked her once why it was never that way to which she’d said, ‘I don’t deserve you there’.</p><p>‘I don’t deserve you there’ he’d repeated to himself under his breath, but before he could ask her what she meant, she continued, ‘You are so romantic. I am romantic only with my words, never with my actions. I sometimes feel I use words as a defence mechanism, trying to overcompensate with them. That is a writer’s curse though. They are so in love with words that there is no space left for people in their hearts. Hemingway never loved truly, Shakespeare and Fitzgerald too.’ Then with a laughter that echoes on his terrace till date , she added ‘Not that they write as well as I do.’</p><p>Word after word, laughter after laughter, thought after thought, she drew him deeper into her, his love breaching the limits envisaged by the drunk poets, yet it refused to stop. He never could comprehend how he would live without her, she never could comprehend how anyone could not live without anyone.</p><p>In love but lonely<br>You and I<br>A wasted life<br>I leave, you die</p><p>Broken hearts, long kisses<br>Lifetime is too long<br>Live more, love less<br>One day, one song</p><p>Look me in the eyes<br>Hold me close and tight<br>Let me cry<br>Today I have no might</p><p>Eighty billion dead, six billion alive<br>One more , one less<br>Who will you remember and forget<br>It’s your guess</p><p>As a teenager, when I read fairy tales and love stories, I never understood how you could love someone so much that the entirety of your being was replaced by a single emotion. Now, I know.</p><p>I kissed her all over Mumbai. Even today, Mumbai tastes of her . She used this rose perfume that I gifted her a lot. It left a fragrant trail wherever she went. Mumbai smells of her too. She loved talking, something you must already have guessed. She talked, talked and then some more. Mumbai sounds like her too.</p><p>‘Solitude is beautiful only when it’s by choice. Sure, you can be alone, but not lonely. But when you’r lonely, you are always alone. Possibilities are infinite when you are with someone, your heart churns image after image of the ways you can love someone, but usually only a small subset of those images become reality, if any at all.</p><p>‘You know why we as a species took to writing? We realised long ago that life had it’s limits. You have 60 odd years, most of them ravaged by the wheels of misfortune and whims of time. So, there’s only so much you can do, experience and act upon right? Thus, we needed a way to capture all that our imagination conceived, for even if they could never become real, they’d at least play out in the minds of our fellow beings. Hence, we wrote. I’ve been talking too much. Why don’t you say something ?’ she told me when we were riding on my bike around Marine drive.</p><p>‘You have a thousand words for me Sunaina, for you, I only have three,’ I said and continued riding in silence.</p><p>I’m sure you must be wondering why this story has Sunaina talking so much and me nothing. It’s simply because anything I say will only be noise in front of her words. They will only take away from her, adding nothing but banality. I knew she loved talking, I knew she loved my listening, and that is how it always was.</p><p>When my kids grew old, I often told them about Sunaina, of her laughter, ideas, charm, beauty and depression. I wanted them to know that love should be all or nothing. Whenever someone tells me they’re ‘not sure’ about someone , I usually say ‘Either you are sure or there’s no love.’ Anything in between is non-existent.</p><p>‘Albert Camus hai to kyaa huaa? Usne buri kitaabe bhi likhi hai’, she told the road side bookseller in Colaba who was trying to charge a premium for Camus. I loved watching her haggle. That someone as fantastical as her, could do something as real as haggling was to me an enchanting sight. She never bought from shops, only from road side sellers.</p><p>‘They need the money, and we need the money’ — she’d tell me. How could anyone be such a surreal combination of the fantastic and the actual?</p><p>Me cappuccino, she cappuccino. Dark, bitter and no sugar. Pink met purple. Six billion people, so many permutations, yet we meet. How? Is it meant to be? That’s a ludicrous poet’s belief. Do we then make do with whom we meet? Ridiculous, she was all that I dreamt of and more. We danced to The Beatles, Rahman and Abba. We cried to Piyush Mishra, Nusrat Fateh Ali Khan, Farida Khanum and Eric Clapton. Two people who loved the same songs and singers just ended up with each other? Bullshit. She read Ghalib to me, quoted Marquez with ease and sang Rumi’s poems. I did what I always did, decorated her voice with my chords. Two people who complemented each other’s talents and needs ended up in each other’s arms as a part of a pre-conceived plan by the universe? The universe does not give a fuck about anyone. Yet we met. We saw Godfather 11 times, Annie Hall 7 times, Begin Again 3 times, Pyaasa 17 times , Children of Heaven 4 times and Manhattan 18 times. Together, she in my lap, me playing with her hair. I loved her hair, the fragrance and the soft touch. We loved whisky and cigarettes. Smoke after smoke, we grew closer. Peg after peg, our conversations became richer.</p><p>‘Illness, death and pain are all public demons. The whole world can see them walking by your side. Depression, is a personal one. Only you can see it. It eats away your soul, one moment at a time. You can talk about it, write about it, read about it and announce it to the world. No one will understand. Nothing will satisfy it’s hunger. At some point in time, you have to make the jump to a more peaceful life. Human love may be limitless, suffering has it’s limits. I loved you Rahul. There’s not much eloquence I can lend to this statement, for words will only dumb down whatever I try to speak. Store me in your poetic memory, the part that’s untouched by time. I will shine bright, reminding you of all that was good.’</p><p>Six billion there were<br>Now one less<br>I leave , relieve myself<br>I know you’ll be a mess</p><p>Shed all tears you can<br>Remember infinite floors<br>You helped all you could<br>Demons called, angels closed all doors</p><p>Love should live on<br>I leave you a dozen letters<br>Read them to your children<br>Remember me , it matters</p><p>Death is easy<br>Living is hard<br>I chose the former<br>Couldn’t put up a facade</p><p>I’m just a grave away<br>I loved you<br>You loved me<br>Start something new.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65a041adeedf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>