Skip to content

Instantly share code, notes, and snippets.

View ubaldop's full-sized avatar
🎣
A fisherman, after all.

Ubaldo Pescatore ubaldop

🎣
A fisherman, after all.
View GitHub Profile

Keybase proof

I hereby claim:

  • I am P3trur0 on github.
  • I am p3trur0 (https://keybase.io/p3trur0) on keybase.
  • I have a public key whose fingerprint is 0C1C ED04 3866 1C2B 0BFB B929 868F 1059 4695 E95A

To claim this, I am signing this object:

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x

Getting Started in Scala

This is my attempt to give Scala newcomers a quick-and-easy rundown to the prerequisite steps they need to a) try Scala, and b) get a standard project up and running on their machine. I'm not going to talk about the language at all; there are plenty of better resources a google search away. This is just focused on the prerequisite tooling and machine setup. I will not be assuming you have any background in JVM languages. So if you're coming from Python, Ruby, JavaScript, Haskell, or anywhere…  I hope to present the information you need without assuming anything.

Disclaimer It has been over a decade since I was new to Scala, and when I was new to Scala, I was coming from a Java and Ruby background. This has probably caused me to unknowingly make some assumptions. Please feel free to call me out in comments/tweets!

One assumption I'm knowingly making is that you're on a Unix-like platform. Sorry, Windows users.

Getting the JVM

@ubaldop
ubaldop / liquidprompt.sh
Created October 20, 2016 13:53
Basic vanilla bash script to provision liquidprompt in Vagrant VMs
#!/bin/bash
if [ ! -f ~/runonce ] #here the check is on the root home directory
then
echo ':::: setting up liquidprompt to vagrant machine ::::'
echo "Installing liquidprompt..."
cd /home/vagrant/
git clone https://github.com/nojhan/liquidprompt.git
source liquidprompt/liquidprompt
@ubaldop
ubaldop / Vagrantfile
Created October 21, 2016 08:42 — forked from bbaaxx/Vagrantfile
Vagrantfile for a cheap ember-cli box (with NVM)
# -*- mode: ruby -*-
# vi: set ft=ruby :
box = 'ubuntu/trusty64'
hostname = 'emberclibox'
domain = 'example.com'
ip = '192.168.42.42'
ram = '512'
$rootScript = <<SCRIPT
@ubaldop
ubaldop / scripted.log
Last active November 10, 2016 18:54
sbtplugin error
Loading global plugins from /home/user/.sbt/0.13/plugins
Loading project definition from /home/user/development/scala/scalagoon/myplugin/project
Set current project to myplugin (in build file:/home/user/development/scala/scalagoon/myplugin/)
[warn] Binary version (2.11) for dependency org.scala-lang#scala-library;2.11.8
[warn] in it.flatmap#myplugin;0.0.1 differs from Scala binary version in project (2.10).
Wrote /home/user/development/scala/scalagoon/myplugin/target/scala-2.10/sbt-0.13/myplugin-0.0.1.pom
:: delivering :: it.flatmap#myplugin;0.0.1 :: 0.0.1 :: integration :: Thu Nov 10 19:46:49 CET 2016
delivering ivy file to /home/user/development/scala/scalagoon/myplugin/target/scala-2.10/sbt-0.13/ivy-0.0.1.xml
Packaging /home/user/development/scala/scalagoon/myplugin/target/scala-2.10/sbt-0.13/myplugin-0.0.1.jar ...
Done packaging.
@ubaldop
ubaldop / build_and_run.sh
Created January 14, 2017 19:28
Script to build and run Freedomotic with a specific plugin
#!/bin/bash
if [[ $# -le 1 ]] ; then
echo 'No plugins parameters provided. Please run the script with a plugin type and name. (e.g.: devices persistence)'
exit 0
fi
freedomoticHome=$(pwd)
echo "Building freedomotic..."
@ubaldop
ubaldop / pattern_matching.erl
Created February 26, 2017 11:40
Second homework solution, Erlang course.
-module(pattern_matching).
-export([exclusiveOr/2,exclusiveOr2/2,exclusiveOr3/2, maxThree/3, howManyEquals/3]).
exclusiveOr(X,Y) ->
not(X==Y).
exclusiveOr2(X,Y) ->
(X=/=Y).
exclusiveOr3(X,Y) when (X and Y) -> false;
@ubaldop
ubaldop / assignment1.erl
Last active February 26, 2017 16:55
Functional Programming with Erlang - Assignment 1
-module(assignment1).
-export([perimeter/1, area/1, enclose/1, bits/1, directBits/1]).
%%%ASSIGNEMENT ABOUT perimeter, area and enclose functions
perimeter({'circle', {_X,_Y}, R}) -> (R+R)*math:pi();
perimeter({'rectangle', {_X,_Y}, H,W}) -> (H+W)*2;
perimeter({'triangle', {_X,_Y}, A,B,C}) -> A+B+C.
area({'circle', {_X,_Y}, R}) -> (R*R)*math:pi();