<?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 Leandro Bolívar on Medium]]></title>
        <description><![CDATA[Stories by Leandro Bolívar on Medium]]></description>
        <link>https://medium.com/@Leandrob13?source=rss-a253000c2c0e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MyJb7yDrT_rVXYtIOOYBCw.png</url>
            <title>Stories by Leandro Bolívar on Medium</title>
            <link>https://medium.com/@Leandrob13?source=rss-a253000c2c0e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 08:46:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Leandrob13/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[Local Variable Propagation with Monix Part 1]]></title>
            <link>https://medium.com/pragmatic-scala/local-variable-propagation-with-monix-part-1-106b80e652bb?source=rss-a253000c2c0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/106b80e652bb</guid>
            <category><![CDATA[monix]]></category>
            <category><![CDATA[scala]]></category>
            <dc:creator><![CDATA[Leandro Bolívar]]></dc:creator>
            <pubDate>Sun, 25 Feb 2018 02:30:07 GMT</pubDate>
            <atom:updated>2018-02-25T02:31:09.396Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been using <a href="https://monix.io/">monix</a> for over a year and a half in the projects I have been involved with and it has proven to be a reliable tool for developing reactive applications due to the stack safety guarantees it provides and the simplicity it offers for composing asynchronous tasks in a functional approach. By the time this article was written, monix is in its third milestone release for version 3.0.0 which adds a feature that was long due: <a href="https://github.com/monix/monix/pull/444">local variable propagation</a>.</p><p>The challenge of local variable propagation does not lie in implementing the Local itself but on how it should get passed throughout the Task execution. One of the main features of Task is stack safety by ensuring trampolined execution and adds as an optimization the deferral of async boundaries, this means, in simple terms, that the given task will run in the current thread until it forces an async boundary. This complicates the passing of the local variable in case that boundary is reached because of the way TaskRunLoop manages its own execution. If we would want to propagate a local var using scala Future we could have a similar approach like the one explained <a href="http://stevenskelton.ca/threadlocal-variables-scala-futures/">here</a>, which will delegate the job to the ExecutionService you implement. For Task, the solution does not lie there and we had to dig deeper to achieve our goal. To sum it up, we had to set the passing of the Local variable when we detect the async boundary has been reached, which specifically we do <a href="https://github.com/leandrob13/monix/blob/94e8be825bbff732bb12c5ff64775f4890391cdc/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunLoop.scala#L65">here</a> and then in the final <a href="https://github.com/leandrob13/monix/blob/94e8be825bbff732bb12c5ff64775f4890391cdc/monix-eval/shared/src/main/scala/monix/eval/internal/TaskRunLoop.scala#L139">callback</a>.</p><p>We have three building blocks for task local propagation, as stated in the javadocs:</p><ul><li><a href="https://github.com/monix/monix/blob/master/monix-execution/jvm/src/main/scala/monix/execution/misc/ThreadLocal.scala">monix.execution.misc.ThreadLocal</a>: Cross-platform equivalent for java.lang.ThreadLocal, for specifying thread-local variables. These variables differ from their normal counterparts in that each thread that accesses one (via its ThreadLocal.get or ThreadLocal.set method) has its own, independently initialized copy of the variable.</li><li><a href="https://github.com/monix/monix/blob/master/monix-execution/shared/src/main/scala/monix/execution/misc/Local.scala">monix.execution.misc.Local</a>: A Local is a ThreadLocal whose scope is flexible. The state of all Locals may be saved or restored onto the current thread by the user. This is useful for threading Locals through execution contexts.</li><li><a href="https://github.com/monix/monix/blob/master/monix-eval/shared/src/main/scala/monix/eval/TaskLocal.scala">monix.eval.TaskLocal</a>: A TaskLocal is like a ThreadLocal that is pure and with a flexible scope, being processed in the context of the Task data type.</li></ul><p>Basically we have aLocal that handles the scope of a ThreadLocal and it is lifted to the Task context with theTaskLocal. Now we can define local variables under the execution of a task with the guarantee that it will propagate the variable when an async boundary occurs. The <a href="https://github.com/monix/monix/blob/master/monix-eval/shared/src/test/scala/monix/eval/TaskLocalSuite.scala">tests</a> to illustrate the behavior are as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f00d92fd11a9ce70dfda07654082813/href">https://medium.com/media/9f00d92fd11a9ce70dfda07654082813/href</a></iframe><p>Every Task.shift implies a forced async boundary so we could assert that in fact the variable is being properly propagated under each scenario. Notice that the propagation of the variables is not by default, we have to define an implicit val opts = Task.defaultOptions.enableLocalContextPropagation in scope so that the task.runAsyncOpt is enabled to pass the local in case an async boundary occurs.</p><p>I have defined additional <a href="https://github.com/leandrob13/monix/blob/feature/taskLocalTests/monix-eval/shared/src/test/scala/monix/eval/TaskLocalSuite.scala#L113">tests</a> to clarify some doubts I had regarding the execution and cleanup of the local vars:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce4ee501dc2a9d7dd1f6cced40a9b6f4/href">https://medium.com/media/ce4ee501dc2a9d7dd1f6cced40a9b6f4/href</a></iframe><p>This is but a summarized look at TaskLocal , now the next step is to define a practical implementation that can facilitate the definition of contexts and the setting and cleaning up of the locals. A proposal will come in a follow up post once I polish some details.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=106b80e652bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pragmatic-scala/local-variable-propagation-with-monix-part-1-106b80e652bb">Local Variable Propagation with Monix Part 1</a> was originally published in <a href="https://medium.com/pragmatic-scala">Pragmatic Scala</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Filter ops with Slick 3.1]]></title>
            <link>https://medium.com/pragmatic-scala/filter-ops-with-slick-3-1-1b0c4ec59bb1?source=rss-a253000c2c0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b0c4ec59bb1</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[slick]]></category>
            <dc:creator><![CDATA[Leandro Bolívar]]></dc:creator>
            <pubDate>Tue, 12 Apr 2016 02:52:50 GMT</pubDate>
            <atom:updated>2016-04-12T02:53:40.308Z</atom:updated>
            <content:encoded><![CDATA[<p>I have been working with slick 3 for a while and the most recurring need I face is filtering queries with predicates that are defined by some optional values, these values often match the properties of the class that is used to map a slick table. For example, lets say I have a table of users:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/450a7e6f939519e156884b01592a9d24/href">https://medium.com/media/450a7e6f939519e156884b01592a9d24/href</a></iframe><p>The usual problem is that I ended up defining a repository function for every property I wanted to filter, ending up with methods like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bbd274282afc30f813dd571b1b720f8/href">https://medium.com/media/8bbd274282afc30f813dd571b1b720f8/href</a></iframe><p>After doing some searching on the internet, I stumbled upon some <a href="https://gist.github.com/cvogt/9193220">proposals</a> and used them as a base to come up with my own solution. The first step was to define some query ops trait that can add the functions I needed to the slick.lifted.Query class. I achieved this by defining an implicit class OptionFilter and adding some help from <a href="http://typelevel.org/cats/">Typelevel Cats</a> functional library:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc6ab9c4337cd39e8b04239436e19a64/href">https://medium.com/media/bc6ab9c4337cd39e8b04239436e19a64/href</a></iframe><p>As you noted, this trait needs an implementation of the HasDatabaseConfig trait which is defined in play-slick. From this part forward I will be assuming the simplest play-slick configuration for Play v2.4.</p><p>The first function, filteredBy, takes an optional value and maps it to the query that is being filtered with the function f. If that value is None, then it returns the unaltered query. The second function, foundBy, takes a list of operations (filter optional predicates), applies them to the table projection of the query, collects the Some values and reduces them according to the boolean operation defined by f. If all the operations defined in ops returned None, then the result will be an empty query. By default this method takes only the first match because I wanted to use it for finding single elements as the findBy function is often used. If you are new into the functional programming concepts, you can checkout what is exactly the Apply Typeclass in <a href="http://typelevel.org/cats/tut/apply.html">here</a>.</p><p>Since we already defined the functions, now it is time to know how to use them. First we need to define a case class that is going to help us with the optional values that we want to pass to the find and filter functions. The UserRepository now looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd681808afd1aac9e87207e439cd82b8/href">https://medium.com/media/dd681808afd1aac9e87207e439cd82b8/href</a></iframe><p>I added the properties I wanted to use as filter parameters to the UserFilter case class, defined them as Option and defaulted them to None. Then I defined the find and list functions so that they take a UserFilter as the only parameter.</p><p>The find function applies to the users TableQuery the list of methods that depend on the value of the desired parameter that we want to filter the query by. If we want the method to apply the corresponding predicates to the underlying filter function, we just need to define the filter value with the desired parameter to Some. At the end, we will reduce those predicates with the OR method. You can eventually add any boolean function that you want in order to reduce the list. In the example I just wish to filter the query to the known unique values of the table since I know the method is defined to return a single element of the query collection.</p><p>The list function users filteredBy in cascade and applies the filter parameter in the same order that every function is called. In the example, I am filtering by three parameters just to keep it simple. As in the previous explanation, the only predicates that will have effect are the ones defined as Some.</p><p>If you want to find a user by its username or filter users by several values, here is how:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe945d3805a1823c6788cfed1d3f9b5a/href">https://medium.com/media/fe945d3805a1823c6788cfed1d3f9b5a/href</a></iframe><p>Time to point out the following:</p><ul><li>I managed to get rid of all the boilerplate I got when defining a function for every parameter I wanted to use in order to filter a query, this was done in a simple and code clean way thanks to Typelevel Cats.</li><li>Implementing GET methods that take multiple query parameters in order to obtain an array of objects is simpler with the help of the filter case class since you don’t have to use for comprehensions to apply each filter to the resulting slick DBIOAction, it is executed on the query and it only takes one trip to the database.</li><li>Functional programming makes your life easier, kind of the whole point I am trying to make with these articles.</li><li>We are showing a simple use case, things get a bit uglier when a join to another table is needed so the resulting list function in the repository might not look as clean as the one above.</li></ul><p>There’s still some things I want to show you about repository implementations because there are two other complications I have faced when coding them. The first one is about dealing with object-relational impedance (yes, that sounds fancy), it means when the user domain object does not perfectly match the UserRegister that I used to map the user table, in this example I assumed the UserRegister was my domain object. The second one is how to manage the operations of nested Scala monads (or, like in some cases, monad-like if you are a purist kind of programmer) that result from calling the repository’s functions (such as Future[Option[User]] or Future[List[User]]). I had to use consecutive map calls or nested for comprehensions for each Scala monad, it was some horrid code. Once again, thanks to Cats library, I was able to get pass this complications and do some interesting things that I will show you in upcoming posts. Any improvements on this example is most welcomed, happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b0c4ec59bb1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pragmatic-scala/filter-ops-with-slick-3-1-1b0c4ec59bb1">Filter ops with Slick 3.1</a> was originally published in <a href="https://medium.com/pragmatic-scala">Pragmatic Scala</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functional Programming, Simpler Unit Testing Part 3]]></title>
            <link>https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-3-c3d52acdd46c?source=rss-a253000c2c0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3d52acdd46c</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[specs2]]></category>
            <dc:creator><![CDATA[Leandro Bolívar]]></dc:creator>
            <pubDate>Wed, 06 Apr 2016 04:21:35 GMT</pubDate>
            <atom:updated>2016-04-16T15:59:09.986Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous part of the series (<a href="https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-2-f85837f42e8a#.ljtow0gau">Functional Programming, Simpler Unit Testing Part 2</a>) I illustrated how we can use mocks and stubs to handle tests for functions that depend on objects that produce side effects. Now we are going to take a look on how we can partially mock classes in order to stub its functions and we can do that with spies, also defined in specs2.</p><p>There are times when we like to assert function calls that we pass to a higher order function but with simple mocks we can’t do a stub of methods that belong to the class we are testing, here is where spies come in handy. We can spy on our tested class and stub the methods we want while normally testing the higher order functions. I simplified the code for AccountServicesSpec2 so that the only test that is defined is for the higher order function applyInterest:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/190be079507fc370667f737d41418529/href">https://medium.com/media/190be079507fc370667f737d41418529/href</a></iframe><p>There are some details to point out:</p><ul><li>In specs2, there is a different way to stub spies. We need to use the doReturn/when methods when specifying the return value of the function when it gets called.</li><li>Since we are now stubbing the methods that produce side effects, there will be no calls to the mocks we defined for AccountRepository and IntegrationServices so we assert that in fact none of the methods of those dependencies gets called.</li><li>There is no need to define a partial function for adding interest, we just use the actual stubbed method of the spied class.</li></ul><p>By using spies we extended the reach of our test for the applyInterest function since it allowed us to assert the calls of methods that we will actually use in the execution of AccountServices, in my humble opinion, it is a very useful trait. This last part of the series wraps it since it was intended to give just a glance of <a href="https://etorreborre.github.io/specs2/">specs2</a>. I remind you that there are <a href="https://github.com/etorreborre/specs2/tree/SPECS2-3.6.4/examples/src/test/scala/examples">examples</a> you can check out if you want to know all you can do with this library.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3d52acdd46c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-3-c3d52acdd46c">Functional Programming, Simpler Unit Testing Part 3</a> was originally published in <a href="https://medium.com/pragmatic-scala">Pragmatic Scala</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functional Programming, Simpler Unit Testing Part 2]]></title>
            <link>https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-2-f85837f42e8a?source=rss-a253000c2c0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f85837f42e8a</guid>
            <category><![CDATA[specs2]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[testing]]></category>
            <dc:creator><![CDATA[Leandro Bolívar]]></dc:creator>
            <pubDate>Wed, 06 Apr 2016 04:10:41 GMT</pubDate>
            <atom:updated>2016-04-23T02:18:26.647Z</atom:updated>
            <content:encoded><![CDATA[<p>In <a href="https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-1-66b7a5c1e1d5#.9neujlq97">Functional Programming, Simpler Unit Testing Part 1</a> I illustrated how we can use higher order functions and function composition in order to deal with methods that produce side effects and how we can test our code more efficiently by isolating these side effects in small functions. I also chose not to test the methods that access the repository and web services because it is better handled by mocking objects, which we will learn in this part of the tutorial.</p><p>There is always an open debate on which is the smallest unit to test in our code, if it is truly isolated or if it should consider other components of code to test the expected behaviour (read Martin Fowler’s blog post about <a href="http://martinfowler.com/bliki/UnitTest.html">Unit Testing</a>). In our example, our units are functions that have specific responsibilities and can describe behaviours or tasks by composing them through higher order functions. We treat with special care those functions that produce side effects so that they remain completely isolated so when the time come to test them, we can deal with the objects that interact with databases or web services through mocks. For such tasks, I use <a href="https://etorreborre.github.io/specs2/">Specs2</a> which is a library that uses Mockito to create the mock objects needed. This testing library is FP oriented and the infix notation helps in making yours tests more expressive and self explanatory.</p><p>Lets go right to the tests. In the <a href="https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-1-66b7a5c1e1d5#.9neujlq97">Account Services class</a> we wrote several functions which we test one by one, including the ones that we skipped in part 1. We define a spec class called AccountServicesSpec, set it up with out mock objects, define a test class that extends AccountsServices so we can overwrite the external dependencies with our mocks, we include the <strong>before</strong> method which is called previous to each spec execution and then we lay down the tests corresponding to each function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d52fe5c3496c5289999f4488ddc5ca74/href">https://medium.com/media/d52fe5c3496c5289999f4488ddc5ca74/href</a></iframe><p>We can point out the following:</p><ul><li>The infix notation is a great help when expressing what we are expecting: <strong>result must have size 1 </strong>in case of asserting the size of a list, <strong>result must beEqualto(0.2) </strong>in case we are expecting a specific value. This makes our tests more explicit and it is easier to maintain or change in case the code gets modified.</li><li>The method <strong>before</strong> is used to do the setup needed before each test so that you don’t have to repeat it in every spec, keeping yourself DRY. It is useful when we need to reset the mock call counter (yes, the mock preserves a counter that it is increased every time it is called and it does not reset itself after each spec is done) and when you need to stub some of the mocked object’s methods or properties.</li><li>Mocking the objects that produce side effects provides us with the isolation needed to test the functions that contain those objects and assert for expected values and method calls. This way we keep our premise: every function is a unit and we can compose complex behaviours by composing the functions that we need. The higher order functions help us contain those functionalities and, in a way, make dependency injection directly to them.</li></ul><p>Specs2 has a lot of more features than those shown in this example, if you want to have a closer look there are <a href="https://github.com/etorreborre/specs2/tree/SPECS2-3.6.4/examples/src/test/scala/examples">specs2 examples</a> available. We still can make more out of this library by using something called <strong>spies</strong>. Spies are partially mocked objects that you can instantiate and use them as we used our AccountServicesTest class but with the ability to stub its functions and assert calls made to them. I am going to leave that to the <a href="https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-3-c3d52acdd46c#.tc3lxtasi">third part of this tutorial</a>. For more insight you can check out the links I included to the Specs2 homepage, the documentation is quite good.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f85837f42e8a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-2-f85837f42e8a">Functional Programming, Simpler Unit Testing Part 2</a> was originally published in <a href="https://medium.com/pragmatic-scala">Pragmatic Scala</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Functional Programming, Simpler Unit Testing Part 1]]></title>
            <link>https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-1-66b7a5c1e1d5?source=rss-a253000c2c0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/66b7a5c1e1d5</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[scala]]></category>
            <dc:creator><![CDATA[Leandro Bolívar]]></dc:creator>
            <pubDate>Wed, 06 Apr 2016 03:32:48 GMT</pubDate>
            <atom:updated>2018-02-24T23:35:24.023Z</atom:updated>
            <content:encoded><![CDATA[<p>From my experience in Scala, one of the most annoying things to do is to test methods that have inner calls to other private or public methods since there is no way to stub them or mock the objects that those methods use or produce. The issue gets more complicated if an inner method call produces side effects (database inserts, web service calls, etc) and you don’t have a way to control how those actions are executed, this compromises the necessary isolation of your unit test. To avoid these testing pains I resorted to functional programming in Scala, implementing anonymous and higher order functions.</p><p>A higher order function, as explained in the <a href="http://docs.scala-lang.org/tutorials/tour/higher-order-functions.html">Scala Documentation</a>, is a function that take other functions as parameters. Lets say we have a bank client that just earned a 10% interest value on all his accounts and you want to apply those changes to it. You will want to query all his accounts, add the 10% interest value to them and store the corresponding results.</p><p>The account domain:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2223859a06a193b4e5e6dba785e4111c/href">https://medium.com/media/2223859a06a193b4e5e6dba785e4111c/href</a></iframe><p>Account Services class:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/312ef14688d82f81058059f34341707c/href">https://medium.com/media/312ef14688d82f81058059f34341707c/href</a></iframe><p>We assume that AccountRepository has all the insert, update, get and delete methods for handling database persistance of our account objects. The IntegrationServices class defines an API for web services, in this case we define one that is responsible for querying the current interest rate. As you can see, the method execute only takes the client id as a parameter, then we just call the inner methods and thanks to the function composition and currying you can see clearly the flow of the process: pass the client id, get the current interest rate, add it to the account’s amount and then update the accounts.</p><p>Now we want to test our AccountServices class with a simple suit made just by asserts. For that we are going to define <a href="http://docs.scala-lang.org/tutorials/tour/anonymous-function-syntax.html">anonymous functions</a> so we can pass expected results to the higher order ones. In these tests we will omit testing the functions that produce side effects, we’ll to learn how to do it using mocking and stubbing in the second part of this tutorial.</p><p>Testing our service:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b86b9c82e116888d468420457f6afdb/href">https://medium.com/media/6b86b9c82e116888d468420457f6afdb/href</a></iframe><p>We can point out the following:</p><ul><li>There are no private methods: every method defined could be tested because they are not defined as private.</li><li>There is no need to test explicitly the method execute: this method is defined so that the client class or object can pass the client id and obtain the expected result. We are only testing the higher order function that gets done the required task.</li><li>No problem with side effects: every function got replaced by an anonymous function with desired results, this way we avoid dealing with unwanted side effects from inner methods which calls cannot be controlled in regular testing.</li></ul><p>There is a much efficient way of testing our example by using mocks and stubs which allow us to assert passed function calls, mock objects that have side effects (like the AccountRepository and IntegrationServices) and test for how our class handles errors (which is not well defined in our example). We will show how to do that in <a href="https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-2-f85837f42e8a#.jk0ouxu0j">part 2 of Functional Programming, Simpler Unit Testing</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66b7a5c1e1d5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/pragmatic-scala/functional-programming-simpler-unit-testing-part-1-66b7a5c1e1d5">Functional Programming, Simpler Unit Testing Part 1</a> was originally published in <a href="https://medium.com/pragmatic-scala">Pragmatic Scala</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>