Functional programming — Flow

What Ifs?!?

https://d.newsweek.com/en/full/1868100/what-if-watcher.png?w=1600&h=1200&q=88&f=c938454f4fe0b6eac89b78d13f210272
main v1 = do
if v1 == 5 then
print "v1 is equal 5"
else
print "No it is not."

Pattern Matching

pmatching 5 = do print "v1 is equal 5"
pmatching _ = do print "No it is not."

Guards

Photo by Maksym Kaharlytskyi on Unsplash
guards v1 
| v1 == 5 = do print "v1 is equal 5"
| otherwise = do print "No it is not."

And my loops?

sumList [] = 0
sumList (x:xs) = x + sumList xs
foldl (+) 0 xs

Now maps and filters

map (\x -> x*2) [1..3] -- outputs [3,4,5]
filter (\x -> x > 1) [1..3] -- outputs [2, 3]

--

--

--

I'm a back-end developer, functional programming lover, fascinated by computer science and languages. From the south part of Brazil to the world

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Changing the architecture of Express.com

Make your own programing language with python.

RISING TALENT

How to create a login screen page in swift 3: authenticate an user and keep the session active

Firebase: What Is Atomicity & How To Accurately Increment/Decrement Values In Cloud Firestore

Git Ready! — Basic Git Workflow

How I Successfully Removed My Ego as a Computer Programmer

Endless staircase

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin Da Silva

Kevin Da Silva

I'm a back-end developer, functional programming lover, fascinated by computer science and languages. From the south part of Brazil to the world

More from Medium

Rosetta Code: Object Oriented Programming Examples

Haskell is great but is hard at the same time…

Haskell Journey: Creating Type

My first 77 hours with Haskell