<?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 Sagar Patel on Medium]]></title>
        <description><![CDATA[Stories by Sagar Patel on Medium]]></description>
        <link>https://medium.com/@srdpatel?source=rss-9f7191286418------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BBYYARF2IGwI5KEicMPsDQ.jpeg</url>
            <title>Stories by Sagar Patel on Medium</title>
            <link>https://medium.com/@srdpatel?source=rss-9f7191286418------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 08:10:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@srdpatel/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[Kotlin: Scope functions]]></title>
            <link>https://srdpatel.medium.com/kotlin-scope-functions-4836d11d1a73?source=rss-9f7191286418------2</link>
            <guid isPermaLink="false">https://medium.com/p/4836d11d1a73</guid>
            <category><![CDATA[function-scope]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Sagar Patel]]></dc:creator>
            <pubDate>Thu, 04 Jun 2020 10:25:21 GMT</pubDate>
            <atom:updated>2020-06-06T23:56:53.146Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*v-tSfWYmZU85xELa.png" /></figure><h3>Prerequisite / Relevant previous articles</h3><ol><li><a href="https://medium.com/@srdpatel/kotlin-function-type-function-literal-lambda-expression-and-anonymous-function-a808034999c3">Kotlin: Function type, higher order function, function literal, lambda expression and an anonymous function</a></li><li><a href="https://medium.com/@srdpatel/kotlin-extension-function-and-receiver-type-c9875ea260a6">Kotlin: Extension function and Receiver type</a></li><li><a href="https://medium.com/@srdpatel/kotlin-inline-function-445f46f05ec0">Kotlin: Inline function</a></li></ol><h3>In a hurry?</h3><p>You can jump to the <strong><em>conclusion</em></strong><em> </em>section and <strong><em>play the concept</em></strong>.</p><h3>Recap</h3><ul><li>We can access the receiver type from the business logic of an extension function through the keyword: <em>this</em></li><li>We can omit the keyword: <em>this</em></li><li>If a lambda has only one parameter, we can access that argument using the keyword: <em>it</em></li></ul><h3>Why scope functions?</h3><p>To make the code more concise!</p><h3>How does the scope function make the code more concise?</h3><p>Let us understand it by an example:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FlgETMgNR4&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2FlgETMgNR4&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1535ad1db3f30368ae9e2d2072fb343/href">https://medium.com/media/a1535ad1db3f30368ae9e2d2072fb343/href</a></iframe><p>As you can see, we could avoid an extra variable. Moreover, we can also omit <em>this</em> keyword as below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FfKscMORoX&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2FfKscMORoX&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/226b1fefaa4b0dc2c38320d347ad7103/href">https://medium.com/media/226b1fefaa4b0dc2c38320d347ad7103/href</a></iframe><p>That was neat and clean. Isn’t it?</p><p>Let us understand our first scope function: <em>with</em></p><h3>With</h3><h4>Definition</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e48e83bdcfdec544b59e8fca3ea4d0a1/href">https://medium.com/media/e48e83bdcfdec544b59e8fca3ea4d0a1/href</a></iframe><p>Let us examine the definition.</p><p>inline</p><p>We use the <em>inline</em> keyword for the higher order function to avoid a function object creation, memory allocation and runtime overhead.</p><p>&lt;T, R&gt; with(receiver: T, block: T.() -&gt; R): R</p><ol><li>It is a generic function.</li><li>It can have anything as the first parameter. We can pass any instance as the first argument.</li><li>Second parameter is a function type, named as block.</li><li>block is an extension function.</li><li>The receiver type of the block is whatever we pass as the first argument to the scope function: <em>with</em>.</li><li>We can access the receiver type T from extension function T.() -&gt; R using the keyword: <em>this</em>.</li><li>The function type parameter is the last parameter in the higher order function <em>with</em>. That means, we can pass our function literal between curly braces as an argument after the <em>with</em> function call parentheses.</li><li>The return type of both the function type parameter and the scope function itself are same: R.</li><li>The return type R is generic. That means, whatever our function literal (that we pass as an argument to our <em>with</em> function) returns, will be the return of our <em>with</em> function.</li><li>In function literals, the last statement gives return.</li></ol><p>So, using <em>with</em>, we can perform multiple operations on an object without explicitly writing the name of the object or without taking another variable.</p><p>However, If the variable is nullable, we cannot avoid that <em>this</em> keyword in <em>with</em>.</p><p>Suppose we were getting a nullable value in our last example from below function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e75bf5a28bc9da31df258dc56b00edf9/href">https://medium.com/media/e75bf5a28bc9da31df258dc56b00edf9/href</a></iframe><p>Handling a nullable variable using <em>with</em> would look like below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FzpQJ21irM&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2FzpQJ21irM&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/512dc81d873ccce2dde76e4443496c9c/href">https://medium.com/media/512dc81d873ccce2dde76e4443496c9c/href</a></iframe><p>That doesn’t look good! There must be a “nullability check” before we perform anything on a “nullable” variable.</p><p>Using another scope function called <em>let</em>, we can perform the “nullability check” and it also reduces the code than above and make it more pretty like below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FEVmOWSnQx&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2FEVmOWSnQx&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/2483ed64c68e958c95e093d61fb01d33/href">https://medium.com/media/2483ed64c68e958c95e093d61fb01d33/href</a></iframe><p>So, let us examine: <em>let</em></p><h3>let</h3><h4>Definition</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b6ae0e66446c284b81d8da151f1a5b9/href">https://medium.com/media/4b6ae0e66446c284b81d8da151f1a5b9/href</a></iframe><pre>&lt;T, R&gt; T.let</pre><p>We know about an extension function. T represents generics here. So, <em>let</em> is a generic extension function. That means, we can use <em>let</em> for any object. It is a member function for every class.</p><p>T.let(block: (T) -&gt; R): R</p><p>Facts:</p><ol><li>let is a higher order function because it has a function type parameter.</li><li>let is also an extension function with a generic receiver type T.</li><li>The receiver type T is also a parameter of the function type block here.</li><li>block is our function type parameter of the let function. We can pass a function type argument using function literal, lambda expression or an anonymous function.</li><li>Because the let function is generic and it has only one parameter which is also a generic, mostly we use function literal to pass as a function type argument.</li><li>The function type parameter block is the only parameter of a higher order function let and the function type has also only one parameter (T) which is also the receiver type. So, while calling let, we can omit the function call parentheses, the parameter of the function type and the arrow -&gt;. We will just write our business logic between curly braces and we can access the parameter (T) of the function type block, using the keyword: it.</li><li>So, we access the receiver type as well as parameter of the function type inside the let block using the keyword: it.</li><li>The return type R is generic. The let function returns whatever our function literal (that we pass as a function type argument for the let function) returns.</li></ol><h4>Why <em>let</em>?</h4><p>Because, we don’t like that “<em>this?.”</em> for a “nullable variable” multiple times!</p><ol><li>To provide “nullability check”.</li><li>To introduce chain operations.</li></ol><p>Wait. What? Chain operations? Let us understand what it is.</p><p>Suppose we have a normal function like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f4145cc674f6e3372605146dccc7421/href">https://medium.com/media/0f4145cc674f6e3372605146dccc7421/href</a></iframe><p>Now, let us do some multiple random operations like below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2F2OfhQ0xBZ&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2F2OfhQ0xBZ&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1cc78e853da1d1817479f4ae03780d4/href">https://medium.com/media/e1cc78e853da1d1817479f4ae03780d4/href</a></iframe><p>Now, let us do the same thing using <em>let</em>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2F1-eyzXmno&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2F1-eyzXmno&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/a944a0cfd57999b5b55bd95861983c11/href">https://medium.com/media/a944a0cfd57999b5b55bd95861983c11/href</a></iframe><p>As you can see, using <em>let</em>, we could avoid new variables while using the return value from multiple chain operations.</p><p>What?! Understanding the example:</p><p>Let us see what we have done (how we have used the <em>let</em> function):</p><ol><li><em>let</em> is a generic extension function. So, any instance can call it. Here, the <em>let</em> function is called on a nullable <em>int</em> variable.</li><li><em>let</em> is also a higher order function. it has only one parameter. The parameter is of function type. The function type parameter has also only one parameter. Hence, we can omit the function call parentheses, the parameter of the function type and the arrow -&gt;. All we write is just our business logic between curly braces and we access the parameter of the function type (which is also the receiver type of our extension function) using the keyword <em>it</em>.</li><li>We have done the same. After the function name which is “<em>let</em>”, there is our business logic between curly braces. The keyword <em>it</em> represents our <em>int</em> instance for the first <em>let block</em> and a <em>StringBuilder</em> instance for the second and third block.</li></ol><p>Few things to note here:</p><ol><li>The last statement in the <em>let</em> block decides the return type.</li><li>We are returning the result and not the receiver type itself.</li><li>We can check the nullability of the receiver type before we proceed.</li><li>It is an extension function. So, we can chain multiple operations. The return type (last statement) of the previous <em>let block</em> will become the receiver type of next function.</li><li>When we want to access the receiver type, we can use the keyword <em>it</em> (We have to use <em>it</em> to access the receiver type).</li><li>We can use any function on the receiver type from the <em>let block</em> using the keyword: <em>it</em>.</li><li>We can pass the receiver type to another function within the let block using the keyword: <em>it</em>.</li></ol><h4>With Vs Let</h4><p>If there is a nullable value or chain operations, use <em>let</em>. Otherwise, use <em>with</em> because we can omit the keyword <em>this</em>.</p><p>Can’t we have a function that can omit the keyword <em>this</em> like a <em>with</em> function and support nullability check and chain operations like <em>let</em>?</p><p>Yes! Our next scope function T.<em>run</em> is a hybrid product which has power of both <em>let</em> and <em>with</em>.</p><p>Let us study: T.<em>run</em></p><h3>T.Run</h3><h4>Definition</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/232667735d6c44f2582b3ebc26b7a9fe/href">https://medium.com/media/232667735d6c44f2582b3ebc26b7a9fe/href</a></iframe><p>The differences between <em>let</em> and T.<em>run</em> functions are:</p><ol><li>The function type parameter</li><li>Return type</li></ol><p>Let us examine it.</p><p>T.run(block: T.() -&gt; R): R</p><ol><li>The receiver type of an extension function and its function type is same: T. That means, we can access the receiver type using the keyword: <em>this</em>.</li><li>The keyword <em>this</em> can be omitted when we want to call any function on it that reduces the code even more.</li><li>It seems that the <em>run</em> function has combined the power of <em>with</em> and <em>let</em>. Or maybe we can say it is a <em>with+</em> version! <em>With</em> was lacking the pros of an extension function (nullability check and chain operations) which the <em>run</em> function satisfies.</li></ol><p>Instead of <em>let</em>, If we use <em>run</em> and rewrite the same function we have written earlier for <em>let</em>, it would look like below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2F_HjqodkY3&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2F_HjqodkY3&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/93361ecd9decf65bd0671401d1b552ef/href">https://medium.com/media/93361ecd9decf65bd0671401d1b552ef/href</a></iframe><p>There are few things common between <em>run</em> and <em>let</em> as below. It will help us in deciding when to use them:</p><ol><li>Both are extension functions.</li><li>Last statement is the return type.</li><li>We can check the nullability before we proceed.</li><li>Extension functions are helpful for chain operations.</li></ol><p>However, there is a small but important difference between them as below. It will help us in selecting the right scope function.</p><p>In <em>let</em>, we access the receiver type using the keyword <em>it</em> and it cannot be omitted. However, in <em>run</em>, we access the receiver type using the keyword <em>this</em> and it can be omitted sometimes.</p><p>So, if we are not passing the receiver as an argument, we better use <em>run</em> because it reduces the code.</p><p>Considering above facts, we can rewrite our last example in a better way like below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FbWzUfvTb8&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2FbWzUfvTb8&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/abee6ea7a3c222fe4b0a232017f56a87/href">https://medium.com/media/abee6ea7a3c222fe4b0a232017f56a87/href</a></iframe><p>StringBuilder(toString()) looks more concise than StringBuilder(it.toString()).</p><p>Similarly, append(&quot; test&quot;) looks more concise than it.append(&quot; test&quot;).</p><p>However, wouldn’t it be more concise if we can replace all <em>$this</em> by <em>$it</em>?</p><p>But how? We have to use <em>this</em> to refer to the context object in <em>run</em>.<br>Correct, but not for “ <em>also</em>”. We can use “<em>it”</em> to refer to the context object while using <em>also</em>.</p><p><strong>Then, how is it different from <em>let</em>?</strong></p><p>“ <em>also</em>” returns the object itself whereas the last statement is “return type” for <em>let</em>.</p><p>Ok, enough theory! Show me code!</p><h3>Also</h3><h4>Definition</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aaea23a413fd87ba3d4b23c648cb6250/href">https://medium.com/media/aaea23a413fd87ba3d4b23c648cb6250/href</a></iframe><pre>T.also</pre><p>It is an extension function. That means, we can use it for “nullability check” before we proceed to work on a nullable value.</p><p>&lt;T&gt; T.also(block: (T) -&gt; Unit): T</p><p>(block: (T) -&gt; Unit)</p><p>block is a function type parameter.</p><p>block has one and only parameter (T).</p><p>We know that if the function type has one and only argument, we can access the argument using the keyword <em>it</em>.</p><p>T , The only parameter of the block is also a receiver type here.</p><p>So, we will be accessing the receiver type T using the keyword: <em>it</em>.</p><p>The interesting part is, it returns the receiver type itself: T</p><p>Using <em>also</em>, We can rewrite our last example code as below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FcFW9SycFP&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2FcFW9SycFP&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/13b4b82eb9647bea1c5048e7f0774934/href">https://medium.com/media/13b4b82eb9647bea1c5048e7f0774934/href</a></iframe><p>As shown in the example, <em>also</em> returns the object itself despite anything written in it’s block and it uses “<em>it”</em> to refer to the context object.</p><p>So, It uses “<em>it”</em> to refer to the context object. That means, if we need to call some methods on the context object, we will have to use “<em>it”</em> like below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2F4henvQOwa&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2F4henvQOwa&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/e397fd5595e2fb03fb519d71b73bd4ec/href">https://medium.com/media/e397fd5595e2fb03fb519d71b73bd4ec/href</a></iframe><p><strong>Can we omit “<em>it”</em> to make the code even more concise?</strong></p><p>Yes! By using <em>apply</em> instead of <em>also</em>!</p><p>Similar to <em>run</em>, <em>apply</em> also uses <em>this</em> to refer to the context object. However, unlike <em>run</em>, being a sibling of <em>also</em>, <em>apply</em> returns the context object itself.</p><p>Let us examine <em>apply</em>.</p><h3>Apply</h3><h4>Definition</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1e7b4632018562ad2314577d101fa970/href">https://medium.com/media/1e7b4632018562ad2314577d101fa970/href</a></iframe><pre>T.apply</pre><p>It is an extension function. Useful for “nullability check”.</p><p>block: T.() -&gt; Unit</p><p>block is a function type parameter.</p><p>The receiver type of an extension function T.apply and it&#39;s function type parameter block is same: T.<br>And we know that we can refer to a receiver type using the keyword: <em>this</em><br>And we also know that we can omit the keyword <em>this</em> while calling a function on it.</p><p>T.apply(block: T.() -&gt; Unit): T</p><p>As we can see, it returns the receiver type itself.</p><p>Let us see how we can include <em>apply</em> in our last example:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2F40U4Bx8MX&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2F40U4Bx8MX&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac292528e3e902aef296322e89ea2883/href">https://medium.com/media/ac292528e3e902aef296322e89ea2883/href</a></iframe><h3>Conclusion:</h3><p>We have scope functions to make the code more concise.<br>All scope functions can be categorized or differentiated by two facts:</p><ol><li>The way to refer to the context object (this or it)</li><li>Return type (the object itself or the last statement)</li></ol><p>Using these two facts, we can decide which scope function to use for a particular situation.</p><p>1) If we need last statement as a return, we have:</p><ul><li>T.run</li><li>T.let</li><li>with</li></ul><p>Anything that the <em>with</em> can do, can be done by <em>T.run</em> also. Clearly, <em>T.run</em> wins here because of it’s added “nullability check” and “chain operation” capabilities.</p><p><em>T.run</em> is better than <em>T.let</em> if we are not passing the receiver type as an argument to another function.</p><p>2) If we want to return the object itself, we have:</p><ul><li>apply (uses <em>this</em> to refer to the object)</li><li>also (uses <em>it</em> to refer to the object)</li></ul><p>Same as the comparison between <em>T.run</em> Vs <em>T.let</em>; <em>apply</em> is better than <em>also</em> if we are not passing the context object as an argument to another function.</p><h3>Play an overview of this article:</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FkZJ0uXHK1&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2FkZJ0uXHK1&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/769f7f01818614b75f40020375e31584/href">https://medium.com/media/769f7f01818614b75f40020375e31584/href</a></iframe><p>That’s all! If you find this article helpful, you can click and hold on that 👏 icon for a few seconds 😉</p><p>Applauds and creative critics are always welcome 😇. Your ❤ motivates me to write more articles.</p><p>Thanks for reading the article! Have a great day 😇.</p><h3>Relevant previous articles</h3><ol><li><a href="https://medium.com/@srdpatel/kotlin-function-type-function-literal-lambda-expression-and-anonymous-function-a808034999c3">Kotlin: Function type, higher order function, function literal, lambda expression and an anonymous function</a></li><li><a href="https://medium.com/@srdpatel/kotlin-extension-function-and-receiver-type-c9875ea260a6">Kotlin: Extension function and Receiver type</a></li><li><a href="https://medium.com/@srdpatel/kotlin-inline-function-445f46f05ec0">Kotlin: Inline function</a></li></ol><p>You can follow me to get the notification when I publish a new article.</p><h3>Let us be Connected</h3><p><a href="https://www.linkedin.com/in/srdpatel">Sagar Patel - Pune, Maharashtra, India | Professional Profile | LinkedIn</a></p><p><a href="https://twitter.com/iSrdPatel">https://twitter.com/iSrdPatel</a></p><p>Tags: kotlin, scopeFunctions, android</p><p><em>Originally published at </em><a href="https://dev.to/srdpatel/kotlin-scope-functions-p4o"><em>https://dev.to</em></a><em> on June 4, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4836d11d1a73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin: Inline function]]></title>
            <link>https://srdpatel.medium.com/kotlin-inline-function-445f46f05ec0?source=rss-9f7191286418------2</link>
            <guid isPermaLink="false">https://medium.com/p/445f46f05ec0</guid>
            <category><![CDATA[inline]]></category>
            <category><![CDATA[inline-functions]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Sagar Patel]]></dc:creator>
            <pubDate>Mon, 04 May 2020 10:41:51 GMT</pubDate>
            <atom:updated>2020-12-28T07:34:15.017Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uOWb9X70Q7JWcNLv.png" /></figure><h3><strong>Prerequisite:</strong></h3><ol><li><a href="https://medium.com/@srdpatel/kotlin-function-type-function-literal-lambda-expression-and-anonymous-function-a808034999c3">Kotlin: Function type, higher order function, function literal, lambda expression and an anonymous function</a></li><li><a href="https://medium.com/@srdpatel/kotlin-extension-function-and-receiver-type-c9875ea260a6">Kotlin: Extension function and Receiver type</a></li></ol><p>We <a href="https://medium.com/@srdpatel/kotlin-function-type-function-literal-lambda-expression-and-anonymous-function-a808034999c3">know</a> that a new function object is created for each and every function type in a higher-order function. It causes memory allocation and hence, runtime overhead. To avoid this or say, to improve the performance, we can use the keyword <strong>inline</strong>.</p><p>However, that doesn’t mean we should inline each and every function! In fact, when we try to <em>inline</em> a function that is not accepting a function type, the IDE will tell us to remove the <em>inline</em> keyword.</p><p>Also, we should not <em>inline</em> any higher-order function that has more than 3 lines because generated code grows a lot for an <em>inline function</em>. You can check the Kotlin standard library to get an idea about when to use inline functions.</p><p>When using an inline function, we are not allowed to pass a function type parameter to another function. However, if it is necessary, we can mark such a function type as a <strong>noinline</strong>.</p><p>Ok, enough theory!</p><p>Let us understand it by an example:</p><p>Suppose we have our higher-order function like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a52f639ae085545a3b33434f9bab0b77/href">https://medium.com/media/a52f639ae085545a3b33434f9bab0b77/href</a></iframe><p>So, in such case, in order to prevent new function object creation, we can make the function inline as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed6609f6204e64ddbab6f750363caf23/href">https://medium.com/media/ed6609f6204e64ddbab6f750363caf23/href</a></iframe><p>However, if we are passing any function type to another function like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8fbcdc2f171b110fc432b9df3a2a3254/href">https://medium.com/media/8fbcdc2f171b110fc432b9df3a2a3254/href</a></iframe><p>Here, the compiler will complain to us: Illegal usage of inline function type ftOne…</p><p>To solve that, we can rewrite our function as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7503949742900578c72dd44019d3a31e/href">https://medium.com/media/7503949742900578c72dd44019d3a31e/href</a></iframe><p>However, if there is only one lambda parameter and we are passing it to another function, it doesn’t make any sense to make such a higher-order function inline and the compiler will also suggest the same!</p><p>Let us understand it by an example:</p><p>Suppose we have a higher-order function like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7c0df27de11e3be92bb3d3904707142/href">https://medium.com/media/d7c0df27de11e3be92bb3d3904707142/href</a></iframe><p>Here, the compiler will tell us to not use the inline keyword when there is only one lambda parameter and we are passing it to another function. So, we can rewrite the above function as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8682cd97bf8508b8b85ed949bb13a28/href">https://medium.com/media/f8682cd97bf8508b8b85ed949bb13a28/href</a></iframe><p>Note that we had to remove the keyword <em>noinline</em> as well because it can be used only for inline functions!</p><p>That’s all!</p><p>If you have read this article, if this article has helped you, you can click and hold on that 👏icon for a few seconds 😉. Your 👏 motivates me to write more articles. 😇</p><p><a href="https://medium.com/@srdpatel/kotlin-extension-function-and-receiver-type-c9875ea260a6">Previous article: Kotlin: Extension function</a></p><p>Where to go from here? What to learn next?: <a href="https://medium.com/@srdpatel/kotlin-scope-functions-4836d11d1a73">Kotlin: Scope function</a></p><p>You can follow me here on <a href="https://medium.com/@srdpatel">medium</a> or on various social networks to get the notification when I publish a new article or to discuss on android development, soft skill development or on various ideas and hacks. Let us become better together.</p><p>Let us learn together from each other’s experience.</p><h3><strong>Let us be Connected</strong></h3><ul><li><a href="https://www.linkedin.com/in/srdpatel">Sagar Patel - Pune, Maharashtra, India | Professional Profile | LinkedIn</a></li><li><a href="https://twitter.com/iSrdPatel"></a></li></ul><p>Tags: kotlin, inline function</p><p><em>Originally published at </em><a href="https://dev.to/srdpatel/kotlin-inline-function-olf"><em>https://dev.to</em></a><em> on May 4, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=445f46f05ec0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin: Extension function and Receiver type]]></title>
            <link>https://srdpatel.medium.com/kotlin-extension-function-and-receiver-type-c9875ea260a6?source=rss-9f7191286418------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9875ea260a6</guid>
            <category><![CDATA[extension-functions]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[receiver]]></category>
            <category><![CDATA[higher-order-function]]></category>
            <dc:creator><![CDATA[Sagar Patel]]></dc:creator>
            <pubDate>Sat, 02 May 2020 01:01:11 GMT</pubDate>
            <atom:updated>2022-08-04T06:18:34.642Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Prerequisite / Previous Article</strong></h3><p>[Kotlin: Function type, Function literal, Lambda expression, and Anonymous function](<a href="https://link.medium.com/fEkk6DpZW5">https://link.medium.com/fEkk6DpZW5</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KINSe0_FyQWGPr-Q.png" /></figure><p><a href="https://dev.to/srdpatel/kotlin-function-type-function-literal-lambda-expression-and-anonymous-function-lbd">Kotlin: Function type, function literal, lambda expression, and An anonymous function</a></p><h3><strong>Extension function</strong></h3><p>General scenario: We make a class. We write a few methods. Later, we realize that we need more methods for the class. We write more methods in the same class.</p><p>But, if the class is in the third-party library that we are using through dependency or in such a way that we cannot add new functions in such a class, we cannot modify that class.</p><p>In kotlin, <strong>we can add a new function for any class in any other class too</strong>. Such a function is called an “Extension function,” and we can <strong>use</strong> it only <strong>inside the class where we create it.</strong></p><p>So now, we can add new functions even for the class that is in the third-party library. Note that it is not limited to third-party library classes only! The main thing is <strong><em>we can add a new function for any class in any other class without inheritance</em>.</strong></p><h3>Syntax</h3><p>In order to create an extension function, we write the class name (also known as a receiver type) followed by a dot, followed by our function as below:</p><pre>//Here, OurClassName is called a receiver type<br> <br>fun OurClassName.ourExtensionFunction</pre><p>For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1fd49c374c00c9d785a2f76292c15de/href">https://medium.com/media/d1fd49c374c00c9d785a2f76292c15de/href</a></iframe><p>We can access an instance of the <strong>receiver type using <em>this</em> keyword inside the business logic,</strong> as shown above.</p><h3>How to call/use an extension function?</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ce830f0ff3960bf91d52d4af68b36fa/href">https://medium.com/media/9ce830f0ff3960bf91d52d4af68b36fa/href</a></iframe><h3>Receiver</h3><p>We have seen a receiver type in an extension function. Similarly, a function type, function literal, lambda expression, and an anonymous function can also have a receiver type.</p><h3>A function type with receiver</h3><p><strong>Syntax/Signature of a function type with receiver:</strong></p><pre>ft: Int.(Int) -&gt; Int // Here, the receiver type is: Int</pre><h3>Function type with the receiver as a parameter</h3><p>We can have a higher-order function having a function type parameter with a receiver as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68472d19a98f983bdcb8740bc78ac4de/href">https://medium.com/media/68472d19a98f983bdcb8740bc78ac4de/href</a></iframe><p>Note that <strong>when a receiver is treated as an argument, it must be the first argument,</strong> as shown in the comment of the above function.</p><p>In order to call the above higher-order function, we can use one of the below things:</p><h3>Function literal with receiver</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da19b73817915f1271b2fbd3b708a794/href">https://medium.com/media/da19b73817915f1271b2fbd3b708a794/href</a></iframe><p>Let us understand our “<em>function literal</em>.”</p><pre>{ y: Int -&gt; this - y }</pre><ul><li>We have passed our function literal as an argument against:</li></ul><p>ft: Int.(Int) -&gt; Int)</p><ul><li>The function type parameter is expecting an Int parameter. Our function literal has also an Int parameter:</li></ul><p>y: Int</p><ul><li>Inside the business logic, we have used the keyword: <em>this</em></li></ul><p>-&gt; this - y</p><ul><li>We access an instance of our receiver in a business logic of an extension function through the keyword: <em>this</em></li><li>Our <em>this</em> keyword has been inferred as a receiver type: <em>Int</em> for:</li></ul><pre>ft: Int.(Int) -&gt; Int</pre><ul><li>Our <em>this</em> keyword refers to a receiver type: <em>Int</em></li></ul><h3>Lambda expression with receiver</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3370aed5f7f55ff2dd9b38ec1dffae2e/href">https://medium.com/media/3370aed5f7f55ff2dd9b38ec1dffae2e/href</a></iframe><p>And then, we can use that lambda to pass as an argument to our higher-order function as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b56ee3671dcbdee30e18ddeabfcc8233/href">https://medium.com/media/b56ee3671dcbdee30e18ddeabfcc8233/href</a></iframe><h3>Same receiver for both an extension function and a function type</h3><p>Suppose we have a higher-order function like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/046f026791c43d9cc196c37ca68739e2/href">https://medium.com/media/046f026791c43d9cc196c37ca68739e2/href</a></iframe><p>So, as shown in the example above: <strong>When the receiver type of an extension function is the same as its function type parameter, we can omit the keyword “<em>this”</em> while calling any function on it</strong>.</p><p>We can call the above extension function like below:</p><p><strong>Using Anonymous function:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/08e355d3282b518bd1b4e086f9985672/href">https://medium.com/media/08e355d3282b518bd1b4e086f9985672/href</a></iframe><p><strong>Using lambda:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d9d0ac8f8ce3ce49049b05aba454405e/href">https://medium.com/media/d9d0ac8f8ce3ce49049b05aba454405e/href</a></iframe><p>You can play the concept below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fpl.kotl.in%2FOKsyHRgjy&amp;display_name=Kotlin+Playground&amp;url=https%3A%2F%2Fpl.kotl.in%2FOKsyHRgjy&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=kotl" width="800" height="300" frameborder="0" scrolling="no"><a href="https://medium.com/media/da100ddfa57a4c2e620b33b1154530bb/href">https://medium.com/media/da100ddfa57a4c2e620b33b1154530bb/href</a></iframe><p>That’s all!</p><p>If you have read this article, if this article has helped you, you can click and hold that 👏 clap icon for a few seconds 😉</p><p><a href="https://dev.to/srdpatel/kotlin-function-type-function-literal-lambda-expression-and-anonymous-function-lbd">Link to the previous article</a></p><p><a href="https://medium.com/@srdpatel/kotlin-inline-function-445f46f05ec0">Next article: Kotlin: Inline function</a></p><p>You can follow me here on <a href="https://medium.com/@srdpatel">medium</a> or on various social networks to get notifications when I publish a new article or discuss android development, soft skill development, or multiple ideas and hacks. So let us become better together.</p><p>Let us learn together from each other’s experiences.</p><p><strong>Let us be Connected</strong></p><p><a href="https://www.linkedin.com/in/srdpatel/">https://www.linkedin.com/in/srdpatel/</a></p><p><a href="https://twitter.com/LogicalSagar">https://twitter.com/LogicalSagar</a></p><p>Tags: kotlin, function type, function literal, lambda expression, an anonymous function, higher-order function, extension function, receiver type</p><p><em>I published the original article at </em><a href="https://dev.to/srdpatel/kotlin-extension-function-1dd7"><em>https://dev.to</em></a><em> on May 2, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9875ea260a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin: Function type, Function literal, Lambda expression and Anonymous function]]></title>
            <link>https://srdpatel.medium.com/kotlin-function-type-function-literal-lambda-expression-and-anonymous-function-a808034999c3?source=rss-9f7191286418------2</link>
            <guid isPermaLink="false">https://medium.com/p/a808034999c3</guid>
            <category><![CDATA[function-literal]]></category>
            <category><![CDATA[anonymous-function]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[lambda-expressions]]></category>
            <category><![CDATA[function-types]]></category>
            <dc:creator><![CDATA[Sagar Patel]]></dc:creator>
            <pubDate>Thu, 23 Apr 2020 11:16:17 GMT</pubDate>
            <atom:updated>2022-08-05T05:45:22.254Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin: Function type, Function literal, Lambda expression, and Anonymous function</h3><h3><strong>Function Type</strong></h3><p>We know data types. Similarly, we have function type too in kotlin.</p><h3>Signature / Syntax</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20728ddd15e53e41776c6d7cd5589e88/href">https://medium.com/media/20728ddd15e53e41776c6d7cd5589e88/href</a></iframe><h3>How to call/execute a function type?</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e0c9708fb48d9c16707b29db11952ba/href">https://medium.com/media/2e0c9708fb48d9c16707b29db11952ba/href</a></iframe><h3>Usage:</h3><h3>Function type as an interface</h3><p>We can implement a function type like an interface in a kotlin class. When we implement a function type, we get a &quot; invoke &quot; method to override a signature similar to the implemented function type.</p><p>Example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb83d94f80870c837777c2085a2d8f9d/href">https://medium.com/media/bb83d94f80870c837777c2085a2d8f9d/href</a></iframe><h3>Function type as a parameter</h3><p>As a function parameter in a higher-order function. The function that takes one or more function types as a parameter/s or/and the function that returns a function type is known as a higher-order function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75052f8414dce713d8302c20e89465f4/href">https://medium.com/media/75052f8414dce713d8302c20e89465f4/href</a></iframe><p>There is one thing to remember here:</p><p>A new function object will be created for each function type of a higher-order function.</p><h3>How to call/use/execute such a higher-order function?</h3><p>We know how to call a function, but we may not know how to pass a function type argument/s in any higher-order function!</p><p>We can pass function type arguments using function literal, lambda expression, or anonymous function. Let us check these all one by one.</p><h3>Function literal</h3><h4>Signature / Syntax: 1</h4><pre>{ comma separated pascal parameters -&gt; business logic }</pre><p>Example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/91c91f51db9e1866980268d4142c8e0a/href">https://medium.com/media/91c91f51db9e1866980268d4142c8e0a/href</a></iframe><p>Note that the last statement in a function literal is considered as a return statement. So, the last statement in a function literal makes the return type.</p><p>We can use function literal to pass as a function type argument for higher-order function as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81328a8fc1ec13171241b3270f42de27/href">https://medium.com/media/81328a8fc1ec13171241b3270f42de27/href</a></iframe><p>OR if the function type parameter is the last in the higher-order function, we can write our function literal after the closing function parenthesis as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/05979440d845e92502b2e60f038578f3/href">https://medium.com/media/05979440d845e92502b2e60f038578f3/href</a></iframe><p>OR if the higher-order function has only one parameter or if the function type parameter is only parameter in a higher-order function like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3543bca099eb96e5c22f5e2ead2ca1d2/href">https://medium.com/media/3543bca099eb96e5c22f5e2ead2ca1d2/href</a></iframe><p>While calling such a higher-order function, we can omit the function call parentheses like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5019e5618f6d735bc62348978497c126/href">https://medium.com/media/5019e5618f6d735bc62348978497c126/href</a></iframe><h4><strong>Syntax / Signature 2</strong></h4><p>Also, if the function type is the only parameter in a higher-order function and if the function type also has only one parameter like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/578c72e711a1a587eebc45bc6fb0c375/href">https://medium.com/media/578c72e711a1a587eebc45bc6fb0c375/href</a></iframe><p>While passing such a function literal, in addition to function call parentheses, we can also omit the parameter and an arrow -&gt; ! We just write core business logic between curly braces and we can access our single parameter through the keyword <em>it</em> like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c63122696c4d038406b4d2d8bbe5c60/href">https://medium.com/media/6c63122696c4d038406b4d2d8bbe5c60/href</a></iframe><p>And if the higher-order function has only one function type parameter and the function type has no parameter like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01d00d6bee852081155e506bcb0e5658/href">https://medium.com/media/01d00d6bee852081155e506bcb0e5658/href</a></iframe><p>We can simply write our business logic between curly braces right after the higher-order function name as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7671c4568363442b875e5dd18358b54b/href">https://medium.com/media/7671c4568363442b875e5dd18358b54b/href</a></iframe><h4>Types:</h4><p>There are two types of function literals.</p><ol><li>Lambda expression</li><li>Anonymous function</li></ol><h3>Lambda expression</h3><p>Lambda expression is another way to define a function concisely.</p><h4>Signature / Syntax 1</h4><p>We can either specify explicit function type and let the data type of parameters be inferred in the below format:</p><pre>nameOfTheLambda: (explicit function type) = { comma separated parameter: Inferred data type -&gt; business logic }</pre><p>Or we can give explicit type annotation to parameters and let the function type be inferred like the below format:</p><pre>nameOfTheLambda: (inferred function type) = { comma separated parameter: Explicit dataType -&gt; business logic}</pre><p>Or we can write both function type and data type of parameter (but why?) like below format:</p><pre>nameOfTheLambda: (explicit function type) = { comma separated parameter: Explicit dataType -&gt; business logic}</pre><p>Let us see an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddef016afd6cb69722145dc26e31d81d/href">https://medium.com/media/ddef016afd6cb69722145dc26e31d81d/href</a></iframe><h4>Signature / Syntax 2 for special case</h4><p>If a lambda has only one parameter, we can omit everything except a business logic inside the curly braces, and we can access the single argument using the keyword: <em>it.</em></p><p>Example:</p><p>Suppose we have a lambda expression like the below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b319d5b5a2f0b57b9283d86babdfb5a1/href">https://medium.com/media/b319d5b5a2f0b57b9283d86babdfb5a1/href</a></iframe><p>We can write the equivalent lambda as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64e909e0562a6c6222a76c682dc7fbf0/href">https://medium.com/media/64e909e0562a6c6222a76c682dc7fbf0/href</a></iframe><p>Summary for a lambda expression having a single parameter</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10e2c94ae42f98a23338c91e0240b1f4/href">https://medium.com/media/10e2c94ae42f98a23338c91e0240b1f4/href</a></iframe><h4>Usage: How to call / execute / use lambda expression</h4><p>We can use the above lambda expression directly like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e52d001f32ffc381f5106e650ff43f50/href">https://medium.com/media/e52d001f32ffc381f5106e650ff43f50/href</a></iframe><p>OR we can pass a lambda as a function type argument to a higher-order function like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d021b29626f211db11ea398a4b205fa4/href">https://medium.com/media/d021b29626f211db11ea398a4b205fa4/href</a></iframe><p>Sometimes, the common term “<em>lambda” </em>represents a function type, function literal, or a lambda expression.</p><h3>Anonymous function</h3><h4>Signature / Syntax</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f31a344b3892c21679a7fbe87b16ca7/href">https://medium.com/media/2f31a344b3892c21679a7fbe87b16ca7/href</a></iframe><p>We can store an anonymous function in a variable like the below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30ab5b4ce33ee836dd0b8f4d1ae9df5a/href">https://medium.com/media/30ab5b4ce33ee836dd0b8f4d1ae9df5a/href</a></iframe><h4>Usage: How to use an anonymous function</h4><p>We use an anonymous function as an argument for a higher-order function like the below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3455794346b544fadcc84d04184abe3/href">https://medium.com/media/a3455794346b544fadcc84d04184abe3/href</a></iframe><p>We can use an anonymous function through a variable to pass as an argument in a higher-order function as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a763cb4361b5b13997984ad8f87cacc/href">https://medium.com/media/8a763cb4361b5b13997984ad8f87cacc/href</a></iframe><p>That’s all! If you have read this article, if this article has helped you, you can click on that clap icon for few times 😉</p><p>Applauds and creative critics are always welcome 😇</p><p>We will learn about extension function and receiver type in the <a href="https://link.medium.com/a92nLrXG95">next part</a>.</p><p>Thanks for reading the article! Have a great day 😇</p><p>You can follow me here on <a href="https://medium.com/@srdpatel">medium</a> or various social networks to get the notification when I publish a new article or to discuss android development, soft skill development, or various ideas and hacks. Let us become better together.</p><p>Let us learn together from each other’s experiences.</p><h3>Let us be Connected</h3><p><a href="https://www.linkedin.com/in/srdpatel">https://www.linkedin.com/in/srdpatel</a></p><p><a href="https://twitter.com/LogicalSagar">https://twitter.com/LogicalSagar</a></p><p>Tags: kotlin, function type, function literal, lambda expression, an anonymous function, higher-order function</p><p>Thanks to <a href="https://medium.com/u/c9a4243d7014">nwillc</a> for reminding me about the implementation of a function type as an interface 😇.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a808034999c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Udacity Google Android Basics Nanodegree Scholarship Experience]]></title>
            <link>https://srdpatel.medium.com/udacity-google-android-basics-nanodegree-scholarship-experience-c7f3508110f5?source=rss-9f7191286418------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7f3508110f5</guid>
            <category><![CDATA[scholarship]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[udacity]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[nanodegree]]></category>
            <dc:creator><![CDATA[Sagar Patel]]></dc:creator>
            <pubDate>Mon, 03 Dec 2018 16:14:16 GMT</pubDate>
            <atom:updated>2018-12-04T23:16:37.693Z</atom:updated>
            <content:encoded><![CDATA[<h3>**Outline**</h3><p><em>The pain you may feel while working towards your goal is worth than regret you may feel later for not doing so…</em></p><p>This is my personal experience in the journey of Udacity Google Android Basics Nanodegree Scholarship that was started on February 7, 2018.</p><p>You can find the first version of this article providing a glimpse of how I got the full scholarship at the below link:</p><p><a href="https://medium.com/@sagarpatel_31573/how-udacity-google-india-challenge-scholarship-has-changed-my-life-c0bb5f8352b5">How Udacity Google India Challenge Scholarship has changed my life</a></p><p>In this article, I will try to cover my experience so far on this lifelong journey.</p><p>So, let me start with the certificate I have received from Udacity for Android Basics Nanodegree Co-created with Google.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/0*mxzOZQGhusdzqI1A" /></figure><p><a href="https://graduation.udacity.com/confirm/WRLLADPW">https://graduation.udacity.com/confirm/WRLLADPW</a></p><h3>**Udacity Magic**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*kDkagfb8dzcbuI21" /></figure><p>Source: <a href="https://tenor.com/view/ftm-harry-potter-wand-gif-7285683">https://tenor.com/view/ftm-harry-potter-wand-gif-7285683</a></p><p>In addition to recommended skill supported, required, preferred and accepted by global giant companies like Google, Amazon, IBM Watson, NVIDIA, Facebook, etc… <a href="https://www.cnbc.com/2018/05/22/udacity-2018-disruptor-50.html">CNBC Third year top 50 Disruptor</a>, Udacity also teaches and gives guidance on how to plan your day in order to get success, how to make use of community, how to learn, handle high complexity, career tips and support that includes resume building, how to find and apply for a job, communication skill, salary negotiation, entrepreneurship skill, and more… Udacity has always gone beyond our expectations… Udacity can literally make you disciplined, focused and more productive.</p><p>Udacity engages every day with innovators, educators, students, administrators, recruiters, hiring managers, entrepreneurs, executives, individuals, startups, and global corporations, to better understand how and where the work of the future will happen. In short, they spend a vast amount of time learning from anyone and everyone about what the future holds, and this is how they are preparing their students for success.</p><p>The magic Udacity did by extremely captivating, enchanting, fascinating, magnetic, energetic and engaging education, activities, best mentorship, community, support and what not… I literally forgot my all pain. Can’t believe? Keep reading… or experience it by yourself…</p><h3>**Quality Assurance**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rf9MQjq5zI3ILcG8" /></figure><p>Image Source and Credit: <a href="http://picpedia.org/handwriting/q/quality.html">http://picpedia.org/handwriting/q/quality.html</a></p><p>Original Author: Nick Youngson — <a href="http://www.nyphotographic.com/">http://www.nyphotographic.com/</a></p><p><strong>Learn from top Industry Experts like:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/0*hQZPGfQdvYMYUszH" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/0*PzQOJlO46S4I7cMy" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/207/0*Heo6nszcGppUe_g6" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/219/0*3ge-Zybqhjp_yxOE" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/226/0*YNd7_-H088OSvvsP" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/218/0*u28Kfddzn909QGwb" /></figure><p>Learning from such experts is an amazing experience. These instructors have great engaging personality, excellent communication skill, expertise in subject and they deliver the knowledge and tips in such a way that you just feel it like a cake walk.</p><p>There are people like me in challenge scholarship who didn’t really have a pure computer background. However, the way we were getting all educational presentation, delivery, explanation through Udacity course videos, slack channel and forum support, it made our journey utterly buttery smooth. We never ever felt single time that we cannot do something. The Udacity system filled such a strong fuel in us that we just focus on something, get it done and move on. If we ever get stuck, we get support from the slack channel, forum, knowledge center, and student hub. Just imagine a system where every single person wants you to grow. We get help from student/s, moderator/s, mentor/s and in every possible way. One can imagine the quality of content by my live example who has got the job as an Android developer without having computer background!</p><h3>**Best Mentorship**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*O2vnc67ZkRATIxw5" /></figure><p>Best Mentorship I have ever got: <a href="https://medium.com/u/ecfa0eae2974">Akshit Jain</a> Sir</p><p>Student Experience Lead <a href="https://medium.com/u/bf91a7a342bd">Udacity India</a></p><p>Akshit sir has the **<strong>great community-building skill**</strong>. He is **<strong>one man army**</strong>. Many students wondered and literally asked Akshit sir how he can manage such a huge community, how he can reply to every single twitter post, how he can solve so many queries from such a huge community!</p><p>I strongly believe that lifestyle, mindset, attitude, vision, and belief system play a major role in our life. If it all reach a certain level of standard, maturity, and stability, it can influence the lives of other people.</p><p>Isn’t it amazing that Udacity has the ability to improve those ingredients of life? Let us see how Udacity is doing so:</p><p>I *<strong>lost</strong>* my only support when I was 16 who promised me on that very last day when he died that he would help me to find or create purpose of my life — My father. With my father, I *<strong>lost my purpose</strong>* in life, went to depression without any realization and was feeling like *<strong>numb for almost 10+ years</strong>*!!! Somehow, I got to know about Udacity Basic Android Course along with Google association and *<strong>Google India Challenge Scholarship</strong>*. I don’t know why and how, but I just applied and got selected for that. Things started getting change from that very moment to extremely positive. Not only I *<strong>could get my dream job but also I am making Android Apps that aims to make thousands of people’s life easy</strong>*!</p><p><strong>How?</strong></p><p>Initially in the course, being an electrical engineer and working in a powerhouse for almost 2+ years, I had no idea about any programming language anymore! However, there must be something in Udacity, course program and Google association, that kept me going on and on. I literally felt thousands of time that *<strong>sympathy, support, acceptance, guidance I ever wanted since long</strong>*, whenever instructors of Udacity told students that it was completely OK to not know things at first but we keep trying and eventually, as time goes by (as we experience it more and more, as we face it more and more), we become more familiar with it. Maybe, I could feel that extremely positive force, push, encouragement, spark from conversations of Google employees with Udacity instructors and from real life stories eventually shown to students during course. Maybe, It was their community, forum, slack who changed me drastically from a completely introvert, shy, chicken-livered person to an extrovert and more than that, a positive person who started to explore more and more, who started to ask questions, who started to help other people and who started to receive positive response he ever wanted since long, since very long!!!!</p><p><em>_When you receive such a continuous support, motivation, encouragement, guidance, feedback, creative criticism, appreciation, praise, roadmap, vision etc… you get the success for sure._</em></p><p>Psycho-physical treatment (Later, I left it all as I was made so involved in the ABND Full scholarship course that I completely forgot my pain), Full-time job (including odd — 1st and 3rd Saturdays), Living outside to hometown as paying guest, Lack of good internet connection in early days (No broadband, only mobile network — Later, we brought one after I got selected for full time scholarship), did not attend marriage of two best friends and engagement of my cousin (who is super close to me!) because Udacity challenge course had a higher priority for me, death of grandmother during the challenge course (I am missing the sweetest sleep I was getting on her lap), cancer recurrence of my brother-in-law (I am still finding a way to communicate with him in such a way that it can make him feels extremely fresh), emotions could make the old Sagar down on the way of Google India Challenge Scholarship, but not the present Sagar anymore.</p><p>So, you can see that Udacity has changed my life drastically positive. It has set my mindset to grow continuously with extreme positive attitude, vision and belief system.</p><h3>**Source of motivation**</h3><p>I would go alphabetically:</p><p>*@Bharat Makwana*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*fM3FIQxoaYUG4h71" /></figure><p>@Bharat Makwana</p><p>His <em>#100DaysOfCode</em> and <em>#301DaysOfCode</em> posts always inspired me to stick to my daily schedule. It was something like, he is doing it every day, why can’t I?</p><p>*@Diana Vile*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/0*ACZ1Ypwy-Gm_KRLA" /></figure><p><a href="https://medium.com/u/a8269b9b7b42">Diana Vile</a></p><p>She is the very first person who guided me everything about ABND. I asked her a lot questions and she answered it all in a very kind and generous manner. She guided me, encouraged me and put trust on me.</p><p>I had felt exhausted many times during ABND due to the job, ABND lessons and tasks, circumstances and all… but then I remember her, she is Working Woman, Wife, and Mother… and a lifelong learner… I used to motivate myself by one question: If she can do it, why I can’t?! I really appreciate her help.</p><p>*@Divya*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/560/0*ppgJIyw9UMGh-5Ka" /></figure><p><a href="https://medium.com/u/fbdfb1c42352">Divya Thakur</a></p><p>ABND, Data science, Hactoberfest, Pytorch — She is a lioness. Excellent communication skill. My first git guru.</p><p>*@Dr. Jaime*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/0*lUeKqc9UJZCgEcOL" /></figure><p><a href="https://www.drjaimek.com/">https://www.drjaimek.com/</a></p><p>My journey in ABND is affected by three major decisions I took.</p><ol><li>Decision to take participation in challenge</li><li>To ask for any kind of help my employer can do regarding ABND as initially I had no broadband connection and rent house I am living in was not properly prepared at that time. I needed a proper location with good internet connection where I can prepare for ABND. Dr. Jaime helped me to get that way and strength on how I can ask for help to my employer and It worked.</li><li>Later in full ABND Scholarship, there was a time when I was required to complete some ABND task anyhow in order to win the challenge. I wanted to win at least one challenge. Good experience of above decision had given me the confidence to ask for help. In spite of any excuse or lie, I directly asked my employer for leave so that I can push my working slot a bit more for ABND Challenge. And it worked again. (Yes, I won the challenge)</li></ol><p>*@Kristine Glazuna*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*64mDQwe7--ugve0s" /></figure><p><a href="https://medium.com/u/14a3a21c36ca">Kristīne Glazūna</a></p><p>Kristine has been with me since the beginning of the course. As she was in AND, I took her help many times to understand some concepts and she never disappointed me.</p><p>Kristine, The person who realized me that the pain I was suffering from was too small compared to what she went through. Her story, nature, attitude towards challenges inspired me to get up again and walk through all physical and emotional challenges I was suffering from. Her story created the “I can” feeling and belief system in me.</p><p>*@Mahima*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*IgAz7gBSBt6MtcZI" /></figure><p><a href="https://medium.com/u/178aa2d084a5">Mahima</a></p><p>Always super active, Profound, extremely curious, object and target oriented, focused, achiever, wonder girl, fully supportive, motivative, productive, down to earth… She was taking participation in every single activity she could and not only limited to ABND Track but also in other activities such as DroidJam, GDG, DevFest, UFest, WomanInTech, GirlScript-SoC, GHCI, Digital Ocean — Hactoberfest and what not… And she was the most active person in helping other fellow mates. If she can do these much of things, can’t I manage two things only? Job and ABND?</p><p>*Mayur Kumar — My brother in law*</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0QpwgqEBMDqQbKDz" /></figure><p>My sister and her family</p><p>My brother-in-law (husband of my sister), Mayur Kumar (We append the word <em>Kumar</em> after the name of sister’s husband to show respect) is very witty from the beginning and even during the cancer treatment. Honestly, I did not really think my sister would handle this situation so strongly. The Courage, strong positive belief system she has been showing since she got to know about this catastrophe is incredible. She is protecting her family like a lioness. I am very proud on her, actually on both, on her full family. Even today, I think twice or may be more than that, before start talking with them to ensure that they feel fresh after talking with me and not emotional. I never want them to remember and realize about the situation they are going through by my any kind of serious emotions that may break into tears or tearful voice at anytime during the conversation. Since I am very emotional and I have found now that my sister is handling this situation in the best way I can imagine, I try to not interrupt them. My sister has great faith in God and she has taught me how to be patient and keep doing our best we can with great positive belief system.</p><p><a href="https://medium.com/u/607b6202cc1b">Michael Hathi</a><br>@Mohammad Faisal<br>@<a href="https://medium.com/@pateltirth454">Tirth Patel</a></p><p>In ABND challenge track, we were asked for collaborative work via github. I had no prior experience with github. It would not be possible for me to take part in that activity without in-depth, step by step help by Michael hathi, Mohammad Faisal and Tirth Patel.</p><p>**Patel-Apps Pvt Ltd**</p><p><a href="https://patel-apps.com/">https://patel-apps.com/</a></p><p>The Company where I am currently working as an Android Developer. As during challenge track, we had no broadband connection in rent house we are living in, It would really be difficult for me to get the full scholarship if I could not get permission to use resources (office and internet) of my company in weekends. Not only that, my employer also gave me leaves whenever I needed to get the things done in ABND and it played a vital role in getting the ABND certificate.</p><h3>**Key Decisions**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Wi698EWbv3nAhDIx" /></figure><p>Source of Image and Credit: <a href="http://www.thebluediamondgallery.com/handwriting/d/decision-making.html">http://www.thebluediamondgallery.com/handwriting/d/decision-making.html</a></p><p>Original Author: Nick Youngson — link to — <a href="http://www.nyphotographic.com/">http://www.nyphotographic.com/</a></p><p>Few key decisions have played a vital role to bring me here and those are:</p><ul><li>Decision to take participation in challenge track.</li><li>Decision to keep the Udacity in priority.</li><li>Decision to be transparent with my employer and ask if my employer can help me somehow whenever I need.</li><li>Decision to utilize the break time during office hours.</li><li>Decision to not give up.</li></ul><h3>**Community**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ug2qXL6bi9m5o3u4" /></figure><p>Image Source and Credit: <a href="http://www.thebluediamondgallery.com/handwriting/u/unity.html">http://www.thebluediamondgallery.com/handwriting/u/unity.html</a></p><p>Original Author: Nick Youngson — link to — <a href="http://www.nyphotographic.com/">http://www.nyphotographic.com/</a></p><ul><li>Meet like-minded people here.</li><li>Find everything relevant and appealing.</li><li>Get the force you need to thrive.</li><li>It really feels like a family.</li></ul><h3>**Engagement**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*T1KhjIxL1z_KduFY" /></figure><p>Image is labeled under free non-commercial reuse</p><p><a href="https://www.army.mil/article/160615/strong_bonds_helps_soldiers_to_strengthen_relationships">https://www.army.mil/article/160615/strong_bonds_helps_soldiers_to_strengthen_relationships</a></p><p>*<strong>Continuous, Creative, Captivating and Magnetic activities</strong>* such as daily quizzes, Question-Answer Sessions, Ask Me Anything Sessions, Project challenges, introduction challenges, webinars by experts on various technical and non-technical topics, webinars by best students, brainstorming, what to do next, how to prepare a resume, how to be prepared for a job, how to get the dream job, success stories of fellow students, public praise, recognition and gifts for winners (who are none other than our fellow mates) of various challenges, social media activities, swags, prizes and a lot more… in addition to *<strong>24*7 support</strong>* on various technical and non-technical topics through the slack channel, forum, knowledge center, student hub, mentor and fellow mates… the progress of other fellow students, personal attention by direct message, email… everything helped us to push our limits and to keep moving on. The experience all these give is really mesmerizing… It keeps the student engaged, *<strong>sets the growth mindset in student</strong>*, motivates and encourages students to keep moving on and on, to keep learning new things, to thrive and to explore more and more. In the end, the habit system created in each and every student, makes the student sincere, dedicated and committed.</p><h3>**Education with Values**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*h_wFPM1EUSrqpcMt" /></figure><p>This image is licensed under Creative Commons license attributes</p><p>Image source and credit: <a href="https://www.flickr.com/photos/quoteseverlasting/9444838957/sizes/o/">https://www.flickr.com/photos/quoteseverlasting/9444838957/sizes/o/</a></p><p>We were asked to engage as much as possible in the community to leave a mark, to leave a good impression, and we were also said that it will benefit us. Let me try to explain how it worked.</p><p>No one is perfect. Everyone is unique and everyone has got distinct quality, ability, talent, skill etc…</p><p>Everyone was watching the progress of other fellow mates and it encouraged each and every student, it created a strong desire in each and every student to push their limits and to keep moving. The feeling was so strong, the urge was so strong that it *<strong>broke hesitation</strong>* that was lying under many students and it made each and every student ask if they don’t know something without any kind of hesitation. This was the first step for students to take and go *<strong>out of their comfort zone</strong>*. Now, the process of transformation would last forever only if it gets enough care and I must say, the way we could get creative criticism, buttery guidance, feedback, follow up, help… it was so powerful that it didn’t hurt any student even though it was happening publicly. So, as a result, it *<strong>filled confidence</strong>* in students. Now just look at next step. The environment was made so positive by giving proper appreciation, public praise and sometimes rewards also that if someone asks a question in the community, a crowd of students *<strong>reach to help</strong>*!</p><p>Did you realize the transformation? Let me show you:</p><p>**<strong>They broke underlying hesitation -&gt; They made us take a step out of our comfort zone -&gt; We asked for help -&gt; They appreciated, praised -&gt; They filled confidence in us -&gt; We got to know something that we didn’t know before -&gt; They prepared us to help other -&gt; We started to help other.</strong>**</p><p>Words can make you or words can break you… use it wisely. Our community has totally nailed it.</p><p>So, what we have learned from our community?</p><p>As I have said in the beginning, in addition to the technical skill required, recommended, expected, supported and guided by global giants like Google, Amazon, facebook etc… We could learn many other soft skills such as communication skill, To ask for help and to help other, kindness and politeness, appreciating other people for their efforts, observation and listening skill (yes, how to listen to someone is a skill), patience, to be open-minded to learn anything from anyone, Always ready to be improved, positive attitude, to be in a journey towards growth…</p><p>Now this is really a rare combination or to be honest, I have never seen it anywhere else. Just look at the management, every single, smallest point they have taken care of it.</p><h3>**System**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DFBMAuWWvHUFvZt7" /></figure><p>Image Source and Credit: <a href="https://pixabay.com/en/monitor-binary-binary-system-1356059/">https://pixabay.com/en/monitor-binary-binary-system-1356059/</a></p><p>Author: <a href="https://pixabay.com/en/users/geralt-9301/?tab=about">https://pixabay.com/en/users/geralt-9301/?tab=about</a></p><p>There was not a single day, not even a single moment when we faced system down or system failure. The team udacity, community, forum, mentors, knowledge center, the student hub, support, guidance, and feedback were always there 24*7.</p><h3>**What I have got?**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pXLypGhsqfaB_KoG" /></figure><p>Image source and credit: <a href="http://www.thebluediamondgallery.com/handwriting/c/customer-satisfaction.html">http://www.thebluediamondgallery.com/handwriting/c/customer-satisfaction.html</a></p><p>Original Author: Nick Youngson — link to — <a href="http://www.nyphotographic.com/">http://www.nyphotographic.com/</a></p><p>From Udacity free android basic course, I got the job. During Udacity Google ABND Scholarship, I got the promotion. In addition to that, I got a vision, roadmap, friends, community, positive and growth mindset, confidence and desire to explore more.</p><h3>**For You**</h3><p>…suddenly I started to receive positive response… did I do anything differently? No.</p><p>There are lot more people who are more eligible than me, who have been working even harder than me, who have been suffering a lot more than me, who have sacrificed a lot more than me, who have been fighting against toughest challenges than I have ever faced… I just want to say them: Don’t stop! Keep trying! Never give up! You are going to achieve far more success than me and you have my best wishes.</p><h3>**End Note**</h3><p>I am open to help anyone. Anyone can reach to me for any matter. I am also a good listener!</p><p>Udacity and Google have helped me to find and upfront my strength and positivity in such a way that I just have started to keep myself ready for any challenge and not only limited to course but for life itself and I could achieve the attitude of focusing on the solution rather than on problem only. So, it is like my new birth, the new life given by Google and Udacity. The journey has just started and I am enjoying it to the fullest.</p><p>For me, It is like my current job is to survive whereas Udacity is to thrive!</p><p>Thank you so much @Udacity and @Google from the bottom of my heart for giving me a new life!</p><h3>Let us be Connected</h3><p><a href="https://www.linkedin.com/in/srdpatel">https://www.linkedin.com/in/srdpatel</a></p><p><a href="https://twitter.com/creativeconflux">https://twitter.com/creativeconflux</a></p><h3>**Udacity Scholars**</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_eCV9MZHHnOAb-9Q" /></figure><p>Image Source and Credit :<a href="https://github.com/piedcipher/ugics-2018-android-basics-wiki">https://github.com/piedcipher/ugics-2018-android-basics-wiki</a></p><p>Would you like to read a story from the people whom I took inspiration? Head over to below links, you will too definitely get some inspiration:</p><p><a href="https://blog.udacity.com/2018/07/5-student-success-stories-from-india.html">https://blog.udacity.com/2018/07/5-student-success-stories-from-india.html</a></p><p><a href="https://medium.com/@mahima.6.ms/udacity-nanodegrees-udacity-propel-heres-what-you-need-to-know-4fb77d908f70">https://medium.com/@mahima.6.ms/udacity-nanodegrees-udacity-propel-heres-what-you-need-to-know-4fb77d908f70</a></p><p><a href="https://medium.com/@apoorvatiwari2345/udacity-in-my-journey-3df4d10930f4">https://medium.com/@apoorvatiwari2345/udacity-in-my-journey-3df4d10930f4</a></p><p><a href="https://www.blog.google/around-the-globe/google-europe/meet-google-and-udacity-nanodegree-graduates-turned-developers/">https://www.blog.google/around-the-globe/google-europe/meet-google-and-udacity-nanodegree-graduates-turned-developers/</a></p><p><a href="https://medium.com/@diana.vile/google-developer-scholarship-front-end-web-dev-phase-1-f8b1e0b9c3af">https://medium.com/@diana.vile/google-developer-scholarship-front-end-web-dev-phase-1-f8b1e0b9c3af</a></p><p><a href="https://www.forbes.com/sites/womensmedia/2014/10/07/how-you-can-build-your-confidence-and-keep-it/#23b40c2925c9">https://www.forbes.com/sites/womensmedia/2014/10/07/how-you-can-build-your-confidence-and-keep-it/#23b40c2925c9</a></p><p>Best Regards,<br>Sagar</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7f3508110f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Wireless Debugging]]></title>
            <link>https://srdpatel.medium.com/wireless-debugging-bad58d0344d7?source=rss-9f7191286418------2</link>
            <guid isPermaLink="false">https://medium.com/p/bad58d0344d7</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[wireless]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[adb]]></category>
            <category><![CDATA[wifi]]></category>
            <dc:creator><![CDATA[Sagar Patel]]></dc:creator>
            <pubDate>Mon, 18 Jun 2018 23:18:19 GMT</pubDate>
            <atom:updated>2018-07-17T11:58:45.846Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>*Wireless ADB*</strong></p><p><strong>Below is a small guide to set up wireless ADB</strong></p><p>Below guide is just for the information. It is useful when our system is connected with the hotspot of our device. Otherwise, if both our device and system are connected to same network through wifi, we can simply use the plugin <a href="https://plugins.jetbrains.com/plugin/7983-android-wifi-adb">Android Wifi ADB</a> OR one of the various apps available for wireless debugging in play store.</p><p><em>Note that windows and linux may require wired connection after every *</em><strong><em>disconnection</em></strong><em>* whereas you may set up your mac to automatically turn on the wireless ADB every time your device is in same network and configuration. However, I don’t have mac so not much information about mac.</em></p><p><em>Also note that before we can set up wireless debugging, our device should not loose the connection.</em></p><p>Let us start:</p><ol><li>First we connect our device with wired set up as we usually do. We make sure that our device is shown as attached device. We can also check it from the terminal window running below command:</li></ol><pre><em>adb devices </em></pre><p>…and we should be able to see our device listed by it’s id. We also make sure that our device and our system both are sharing *<strong>common network*</strong> (I.e., both are connected with same network. E.g., Our system is connected with our device’s network through hotspot).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PxLv4TEJNZdbv6NB5Hacwg.png" /></figure><p>Some devices have an option like <em>ADB over network </em>in <em>developer options</em>. If our device too has such option, we should enable it.</p><p>2. From the terminal window, we run below command:</p><pre><em>adb tcpip 5555</em></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GBy6uYCgUyHTwCOqGtp2CQ.png" /></figure><p>Here, <em>5555</em> is the port we are explicitly giving.</p><p>3. Now we need the <em>ip address </em>of our device. To know <em>ip address </em>of our device, we run below command:</p><pre><em>adb shell ifconfig</em></pre><p>OR</p><pre><em>adb shell netcfg </em></pre><p>…and from the list of information, we can get the <em>ip address </em>of our device.</p><p>4. Then we run:</p><pre><em>adb connect *</em><strong><em>our ip address*</em>.</strong></pre><p>For example:</p><pre><em>adb connect 192.168.0.162 </em></pre><p>and we should see the message like:</p><pre><em>Connected to 192.168.0.162:5555</em></pre><p>5. Now we can disconnect the data cable and can do wireless debugging as long as our device and system are in same network.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bad58d0344d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set color state list with alpha programmatically in android?]]></title>
            <link>https://srdpatel.medium.com/how-to-set-color-state-list-with-alpha-programmatically-in-android-818a844ca332?source=rss-9f7191286418------2</link>
            <guid isPermaLink="false">https://medium.com/p/818a844ca332</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[alpha]]></category>
            <category><![CDATA[colors]]></category>
            <category><![CDATA[programmatically]]></category>
            <category><![CDATA[color-state-list]]></category>
            <dc:creator><![CDATA[Sagar Patel]]></dc:creator>
            <pubDate>Sun, 13 May 2018 23:57:40 GMT</pubDate>
            <atom:updated>2018-05-13T23:57:40.492Z</atom:updated>
            <content:encoded><![CDATA[<p>Just call the below setColorStateList(int color) method on your View.</p><p>We have given 50% transparency by 128 but we can set it to any number between 0 to 255.</p><pre>private void setColorStateList(int btnTxtColor) {<br>   int[][] states = new int[][]{<br>           new int[]{android.R.attr.state_pressed},<br>           new int[]{android.R.attr.state_focused},<br>           new int[]{android.R.attr.state_enabled}<br>   };</pre><pre>   int[] colors = new int[]{<br>           getAlphaTxtColor(btnTxtColor),<br>           getAlphaTxtColor(btnTxtColor),<br>           btnTxtColor<br>   };<br>   ColorStateList colorStateList = new ColorStateList(states, colors);<br>   setTextColor(colorStateList);<br>}</pre><pre>private int getAlphaTxtColor(int color) {<br>   return ColorUtils.setAlphaComponent(color, 128);<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=818a844ca332" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Udacity Google India Challenge Scholarship has changed my life?]]></title>
            <link>https://srdpatel.medium.com/how-udacity-google-india-challenge-scholarship-has-changed-my-life-c0bb5f8352b5?source=rss-9f7191286418------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0bb5f8352b5</guid>
            <category><![CDATA[experience]]></category>
            <category><![CDATA[udacityindia]]></category>
            <category><![CDATA[success]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[udacity]]></category>
            <dc:creator><![CDATA[Sagar Patel]]></dc:creator>
            <pubDate>Sun, 13 May 2018 23:39:39 GMT</pubDate>
            <atom:updated>2018-09-03T13:51:34.518Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>“If I can do it, you can too. Anyone can do it”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vuCl2DXj0PRo6SpgYb36xg.jpeg" /></figure><p>Depression, anxiety, sleepy head, decreased ability to think with numbness and IBS (Irritable Bowel Syndrome) are a few problems I am going through and currently taking treatment for the same.</p><p>I <strong>lost</strong> my only support when I was 16 who promised me on that very last day when he died that he would help me to find or create the purpose of my life — My father. With my father, I <strong>lost my purpose</strong> of life, went into depression without any realization and was feeling like <strong>numb for almost 10+ years!</strong>!! Somehow, I got to know about Udacity Basic Android Course along with Google association and <strong>Google India Challenge Scholarship</strong>. I don’t know why and how, but I just <strong>applied and got selected</strong> for that. Things started getting change from that very moment to extremely positive. Not only I <strong>could get my dream job, but I am also playing an important role at </strong><a href="http://ccs.sg/"><strong>Capstone Consulting Services, Singapore</strong></a><strong> and </strong><a href="https://patel-apps.com/"><strong>Patel-Apps, Ahmedabad</strong></a><strong> who are</strong> <strong>doing Mobile application development and Web development that aims to make thousands of people’s lives easier!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8dxEOBnbPk5EuXswsIeIXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*FgDyWctroiZti8Yt0yllnA.png" /></figure><p>Initially in the course, being an electrical engineer and working in power house for almost 2+ years, I had no idea about any programming language anymore! However, there must be something in Udacity, course program and Google association, that kept me going on and on. I literally felt thousands of times that <strong>sympathy, support, acceptance I ever wanted since long</strong>, whenever instructors of Udacity told students that it was completely OK to not know things at first, but we keep trying and eventually, as time goes by (as we experience it more and more, as we face it more and more), we become more familiar with it. Maybe, I could feel that extremely positive force, push, encourage, spark from conversations of Google employees with Udacity instructors and from real life stories eventually shown to students during the course. Maybe, It was their community, forum, slack who changed me drastically <strong>from a complete introvert, shy, chicken — livered person to an extrovert and more than that, a positive person who started to explore more and more, who started to ask questions, who started to help other people and who started to receive positive response he ever wanted since long, since very long!!!!</strong></p><p>Psycho-physical treatment (Later, I left allopathic psychological treatment and started homeopathic treatment along with exercise, breath regulation and yoga), Full time job (including odd — 1st and 3rd Saturdays), Living outside to hometown as paying guest, Lack of good internet connection (No broadband, only mobile network), did not attend marriage of two best friends because Udacity challenge course had higher priority for me, death of grandmother during the challenge course and emotions could make the old Sagar down on the way of Google India Challenge Scholarship, but not the present Sagar anymore.</p><p><strong>I am open to help anyone. Anyone can reach to me for any matter. I am also a good listener!</strong></p><p>Udacity and Google have helped me to find and upfront my strength and positivity in such a way that I just have started to keep myself ready for any challenge and not only limited to course, but for life itself and I could achieve the attitude of focusing on solutions rather than on problem only. So, it is like my new birth, new life given by Google and Udacity. The journey has just started and I am enjoying it to the fullest.</p><p><strong>For me, It is like my current job is to survive, whereas Udacity is to thrive!</strong></p><p>Thank you so much <a href="https://medium.com/u/2929690a28fb">Udacity</a>, <a href="https://medium.com/u/bf91a7a342bd">Udacity India</a> <a href="https://medium.com/u/ecfa0eae2974">Akshit Jain</a> and <a href="https://medium.com/u/991272e72e68">Google Developers</a> <a href="https://medium.com/u/123987db5653">Google B2B Team</a> from the bottom of my heart for giving me new life!</p><p>Best Regards,<br>Sagar</p><p><em>P.S.:_ Not only I could achieve full scholarship later, but I could win project challange also and received some cool prizes as well!!!.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*jKPae65--es-KPPfJ3b3dg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*XLMg4Djo3T4A3WQ1sSC8mw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cZK5etpc6xH2LLiGVv2_Lw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0bb5f8352b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>