Introduction
Have you ever been to a scala conf and told yourself "I have no idea what this guy talks about?" did you look nervously around and see all people smiling saying "yeah that's obvious " only to get you even more nervous? . If so this post is for you, otherwise just skip it, you already know fp in scala ;)
This post is optimistic, although I'm going to say functional programming in scala is not easy, our target is to understand it, so bare with me. Let's face the truth functional programmin in scala is difficult if is difficult if you are just another working class programmer coming mainly from java background. If you came from haskell background then hell it's easy. If you come from heavy math background then hell yes it's easy. But if you are a standard working class java backend engineer with previous OOP design background then hell yeah it's difficult.
Scala and Design Patterns
An interesting point of view on scala, is looking at it's set of features as design patterns. This is exactly what Ivan Nikolov says in Scala Design Patterns . He actually shows how the hybrid nature of the scala programming language also makes some of the traditional object-oriented design patterns obsolete, or possible, using other cleaner techniques in his great book. While I fully agree with him, I recognize that it's going to take lot of time going over all the standard design patterns and not only the standard ones but also many of th enon written patterns, best practices, and seeing how the match in the scala programming language.
Terminology
Let's start with the terminology, monad, semigroup, functor, typeclass, higher order functions, higher order types, partially applied functions, partial functions, are you still with us? If you already know the above concepts then this post is not for you but if you don't then heck yeah, but I have no chance of going through them in a single post, so stay tuned for the next post.
Example, is it simple
Question, is the below code easy?
object Request {
def pure[A](a: A): Free[Requestable, A] =
Free.liftFC(Pure(a) : Request[A])
def fetch[A](service: Service[A]): Free[Requestable, A] =
Free.liftFC(Fetch(service) : Request[A])
}
Not for me, what are all those "Free", "lift", "pure", what are the generics doing there? I can find thousands of examples like this, just search google for the cool FP terminology, this is our target to decompose this structure, to clear out the fog.
Haskell
I think if you want to learn scala you first need to learn haskell or something else and only then get to scala. It looks like its very difficult to first get to these concepts by scala. And yes when I need to learn a concept in scala guess what I first learn it in haskell and only then get to scala. if haskell would only have all java libraries and run on jvm...
FP is very important
But FP is very important, concurrency, better code, big data, parallel computing, better testing. I mean FP is the thing for a programmer who want's to write clean code with a clean pure core and all the IO surrounding it, it's the dream of clean code, so we are going to make that effort.
The good thing about FB
The good thing about FP is what makes all the problem and noise. With FP you use pure functions, this I assume we all know what it means. The problem is that real world applications are not pure, they have side effects. And this is where much of the complexity comes into play, this is the challenge, in addition you don't mutate things, so you start using recursion :)
The benefits of imperative programmers
Before i'm getting assassinated by functional programmers I want to tell you this, there are good things about imperative programming. If you have some basic sanity of clean code practices and you write well organized and clean code with imperative programming, (small functions, mutation where needed but not always), you use for loops instead of map/flatMap twin brothers. Then you know what? you use the java util concurrency building blocks and non blocking io also with multithreading, you can write excellent applications which have high performance utilization, I know this from first hand, I wrote many such apps some with very high scale demand, and i have to say that for other programmers without majour knowledge in FP those imperative programs were much easier to understand than their FP mirror brothers and sisters programs. So imperative is also good. But we are here to get to FP not to imperative. And this is the route we are going to take.
Declarative vs Imperative
So the first step is to understand what declarative code means.
I like jenkov article "The illusion of declarative code". He presents the below imperative code:
function capitalWithInterest(capital, interest, periods) {
var result = capital;
for(var i = 0; i < periods; i++) {
result = result * (1 + interest);
}
return result;
}
Now he asks what is the declarative version of that code? and he answers:
var result = capitalWithInterest(100, 0.1, 5);
Here - it's declarative we didn't say imperatively how we want to calculate capital with interest we have just told the computer that we want it to calculate for us the capital with interest.
Declarative code with scala
So in scala the most common example of declarative code is by using "map" and friends instead of for loops, for loops are the explicit imperative way to tell the computer how to do the loop and map and friends are declarative you just tell the computer go over the items on this list and subtract 2 from each
val listOfNumbers = List(1,2,3)
listOfNumbers.map(_ - 2).foreach(println)
So in this case instead of imperatively going through the list and printing each we tell odersky, hey please for each item in the list (map) please subtract two and for each item print it (after you subtracted 2 from it)
Functional Programming and Immutability
Because in functional programming we would rather have pure functions, then, there is a consequence to that the consequence, is that we use immutability more nad more, as much as we can in favour of mutable data structures. In the great book Scala Design Patterns by Ivan Nikolov, the author says, quote: "Immutability is an important principle in Scala and it should be preferred. The builder design pattern with case classes uses immutable fields and this is considered a good practice.". And yes case classes which inherit from sealed traits are not only a great way to model your data, they help extensively with using immutable data structures instead of mutable.
Summary
We have just touched the tip of the iceberg here, but don't worry before global warming takes it's place and metls the iceberg we are going to hit upon all the concepts you wanted to know about scala but had nightmares about free monad, managing state, functors and friends.
Nice and Great information on
ReplyDeleteScala Certification
I have found great and massive information on
ReplyDeleteWorkday payroll training
Workday financials training
Workday training
Python online training
Mulesoft training
Servicenow Online training
Java training
Salesforce training
Mulesoft Online Training
which helps you also. Thanks for Posting
Very useful to me for this content . Thanks for posting the article.
ReplyDeletetechnical and non technical
latest artificial intelligence
ccna career opportunities
short term courses with high salary in india
cyber security interview questions
Very useful to me for this content . Thanks for posting the article.
ReplyDeletetechnical and non technical
latest artificial intelligence
ccna career opportunities
short term courses with high salary in india
cyber security interview questions
Thanks for spending all your pleasant time to make such a Creative content for us. AWS Training in Chennai
ReplyDeleteadana escort - adıyaman escort - afyon escort - aksaray escort - antalya escort - aydın escort - balıkesir escort - batman escort - bitlis escort - burdur escort - bursa escort - diyarbakır escort - edirne escort - erzurum escort - eskişehir escort - eskişehir escort - eskişehir escort - eskişehir escort - gaziantep escort - gebze escort - giresun escort - hatay escort - ısparta escort - karabük escort - kastamonu escort - kayseri escort - kilis escort - kocaeli escort - konya escort - kütahya escort - malatya escort - manisa escort - maraş escort - mardin escort - mersin escort - muğla escort - niğde escort - ordu escort - osmaniye escort - sakarya escort - samsun escort - siirt escort - sincan escort - tekirdağ escort - tokat escort - uşak escort - van escort - yalova escort - yozgat escort - urfa escort - zonguldak escort
ReplyDeleteno deposit bonus forex 2021 - takipçi satın al - takipçi satın al - takipçi satın al - tiktok takipçi satın al - instagram beğeni satın al - instagram beğeni satın al - google haritalara yer ekleme - btcturk güvenilir mi - izlenme-satin-al.com - numarasmsonay.com - borsagazete.com - takipcisatinals.com - izlenme-satin-al.com/youtube - google haritalara yer ekleme - altyapısız internet - mikrofiber havlu - forexbonus2020.com - tiktok jeton hilesi - tiktok beğeni satın al - microsoft word ücretsiz indir - misli apk indir - binance güvenilir mi - takipçi satın al - mikrofiber havlu - uc satın al - takipçi satın al - takipçi satın al - finanspedia.com
ReplyDeleteadanaescort01.com - adiyamanescortxx.com - afyonarackiralama.net - aksarayescort.net - antalyaoyunpark.com - aydinescortkiz.com - balikesirescortlar.com - batmanescortlar.com - bitlisescortlar.com - burdurescortlar.com - bursamalaysias.com - diyarbakirambar.com - edirnedespor.com - erzurumyolkosusu.com - eskisehirescortlari.com - gaziantepekspres.org - gebzeescortkiz.com - giresunmaraton.com - hataykoleji.com - ispartakpss.com - karabukteknik.com - kastamonuajans.net - kayserivalisi.com - kilisescort.com - kocaeliescortlar.com - konyaescortlar.com - kutahyaizemlak.com - malatyadataksi.com - manisaescortlar.com - marasatasoyemlak.com - mardinfanatik.com - mersinmoda.com - muglaapart.net - nigdeyapi.com - orduescortt.com - osmaniyeyorum.com - sakaryanur.com - samsunescortlar.com - siirteyatirim.com - sincanoto.com - tekirdagescortlar.com - tokatforum.com - usakbasin.com - vanescortilan.com - yalovadaemlak.com - yozgattanal.com - sanliurfadayim.com - zonguldakescort.com
ReplyDeleteinstagram takipçi satın al
ReplyDeleteinstagram takipçi satın al
takipçi satın al
takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
aşk kitapları
tiktok takipçi satın al
instagram beğeni satın al
youtube abone satın al
twitter takipçi satın al
tiktok beğeni satın al
tiktok izlenme satın al
twitter takipçi satın al
tiktok takipçi satın al
youtube abone satın al
tiktok beğeni satın al
instagram beğeni satın al
trend topic satın al
trend topic satın al
youtube abone satın al
beğeni satın al
tiktok izlenme satın al
sms onay
youtube izlenme satın al
tiktok beğeni satın al
sms onay
sms onay
perde modelleri
instagram takipçi satın al
takipçi satın al
tiktok jeton hilesi
pubg uc satın al
sultanbet
marsbahis
betboo
betboo
betboo
kayseri escort - hatay escort - kayseri escort
ReplyDeleteinstagram takipçi satın al
ReplyDeleteucuz takipçi
takipçi satın al
https://takipcikenti.com
https://ucsatinal.org
instagram takipçi satın al
https://perdemodelleri.org
https://yazanadam.com
instagram takipçi satın al
balon perdeler
petek üstü perde
mutfak tül modelleri
kısa perde modelleri
fon perde modelleri
tül perde modelleri
https://atakanmedya.com
https://fatihmedya.com
https://smmpaketleri.com
https://takipcialdim.com
https://yazanadam.com
yasaklı sitelere giriş
aşk kitapları
yabancı şarkılar
sigorta sorgula
https://cozumlec.com
word indir ücretsiz
tiktok jeton hilesi
rastgele görüntülü sohbet
erkek spor ayakkabı
fitness moves
gym workouts
https://marsbahiscasino.org
http://4mcafee.com
http://paydayloansonlineare.com
marsbahis
ReplyDeletebetboo
sultanbet
marsbahis
betboo
sultanbet
Great post again! great job. And I am satisfied to read your article. Turkish e visa is online, easy and fast. you can fill your visa application form turkey & within 24 hour you can get your visa.Travelers entering Turkey are required to apply for an e-visa.
ReplyDeleteExellent blog. Thanks again. Nice... Foreign Citizens can easily apply for the Indian 30 days tourist visa, The process is completely online. And Within 5 to 10 minutes Foreign can apply for an Indian tourist e-visa.
ReplyDeleteI am practically satisfied with your great work. Aw, this was a really nice post. As per the latest instructions from the Government of Kenya, all foreign travelers eligible to visit Kenya must complete a kenya health surveillance form online to meet the COVID-19 safety requirements to enter the country.
ReplyDeleteI read your blog now share great information here. Vonex phones
ReplyDeleteReally liked the informative article.Keep sharing more interesting and informative articles with us...emergency Indian visa for US citizen, it is India Visa Online that allows foreign visitors to come to India for five major purposes, business/recreational short term courses, tourism, medical trips or conferences allows for. The applicant can get his/her urgent visa within 1 to 3 days.
ReplyDeleteI have read this article many times, and I found it very helpful. I really appreciate the time and effort you put into this and click here to apply for an emergency business visa India. An e-visa to India has now become easier to obtain.
ReplyDeleteWow.. Very informative article thanks for sharing please keep it up. If you want to travel to India in an emergency and you don't know how to get emergency visa for India, you should visit India e visa website.
ReplyDeleteHow to Deal with Search Not Working in Outlook?
ReplyDeleteIf you are looking for the steps for search not working in Outlook then you need to start by going through simple troubleshooting steps to deal with it. Before diving into the Outlook specific fixes, you need to use the Windows troubleshooters. To start with Windows search troubleshooter,start > settings >update and security. From here, choose the troubleshoot, proceed to the additional troubleshooters and then choose search and indexing option. Lastly, run the troubleshooter. Follow these steps to deal with Outlook search is not working problem.
I can't believe I've never been to this site before, but after going through some of the posts I realized it's new to me. Anyhow, I'm glad I found it and I'll be bookmarking and checking back often. You can fill your visa application form online within 5 to 10 minutes and pay your India visa cost once you complete the form. India e visa cost depends on your nationality and your visa type. cost of Indian visas are always submitted after form submission.
ReplyDeleteHi! I thought I had been to this site before, but after looking through some of the posts, I realized it was new to me. Anyway, I'm glad I found it and I'll definitely be bookmarking it and checking back often. You can fill your visa application form online within 5 to 10 minutes and pay your India visa cost once you complete the form. India e visa cost depends on your nationality and your visa type. The cost of Indian visas is always credited after the submission of the form.
ReplyDeleteYahoo! users, may find it useful to set their homepage to the Yahoo! website. To find out how to make Yahoo my homepage, click the Chrome menu button and select Settings, then check the box for "Show Home button." This will be found in the "Appearance" section of your browser. Then, click the "Change" link, and this will allow you to select the Yahoo! page that will open when you click the home button. Now select "Open this page" and enter the Yahoo! page you want to use as your home page.
ReplyDeleteYou can travel in India and see the beauty of this country, Delhi is a union territory within India, as well as a city, and it consists of two different worlds: New Delhi and Old Delhi. and travel in Delhi Indian City Tour, Famous 15 tourist places in Delhi, you can read about ideas related to this place through Indian Evisa website can read.
ReplyDeletei am enjoying every bit of it. it is a good site, as well as the stock is well-chosen. thank you.. Indian e visa photo, photo requirements for Indian visa, you can read online India e visa photo requirements through the India evisa website.
ReplyDeletebitcoin nasıl alınır
ReplyDeletetiktok jeton hilesi
youtube abone satın al
gate io güvenilir mi
referans kimliği nedir
tiktok takipçi satın al
bitcoin nasıl alınır
mobil ödeme bozdurma
mobil ödeme bozdurma
Hello everyone, Turkish work visa online, you can apply online for a visa to work in Turkey. In fact, it is a very quick, cheap and easy way to get a Turkish work visa.
ReplyDeleteFon Perde Modelleri
ReplyDeleteNumara Onay
turkcell mobil ödeme bozdurma
nft nasıl alınır
Ankara evden eve nakliyat
Trafik Sigortası
DEDEKTÖR
web sitesi kurma
aşk kitapları
Such a very informative article... Thanks for sharing this information... Foreign travelers who want to visit India for vacation, sightseeing, and purpose to enjoy need a tourist visa India, for more information, click and check.
ReplyDeleteYour site has excellent web content.I believe there was a great potential to change my mind once again after reading this article. I'm creating like you. If you are willing to travel to India, you will need a visa. Apply e visa to Indian online. Do you have any questions regarding e Visa India documents? You can find all frequently asked questions with the answers on eta Indian e visa website. You can also contact the visa support center by phone or by email. Apply for your visa easily and quickly.
ReplyDeleteHello, I wanted to write a little Info related to Visa. Are you interested in traveling to any country? Yes, you can apply for an e visa online. You can fill out your visa application form online within 5 to 10 minutes via our Visacent website. We offer visas to citizens of over 190 countries. You can read more info about visas via our website.
ReplyDeleteHello friends, many people ask, how can I apply for a visa? You can e visa apply online. And your visa processing time depends on your nationality and your visa type.
ReplyDelete