Skip to content

Instantly share code, notes, and snippets.


Daniela Sfregola DanielaSfregola

View GitHub Profile
View GraphQLRequest.scala
package io.paytouch.ordering.graphql
import org.json4s.JsonAST.JObject
* Created by danielasfregola on 19/10/2017.
case class GraphQLRequest(query: String, operationName: Option[String], variables: JObject = JObject())
DanielaSfregola / Applicative.scala
Last active Aug 16, 2020
View Applicative.scala
trait Applicative[Box[_]] extends Functor[Box] {
def pure[A](a: A): Box[A]
def ap[A, B](boxF: Box[A => B])(boxA: Box[A]): Box[B]
View Feedback on cats 1.0-MF migration
Overall, quite easy -- but I had to read ALL the release notes quite carefully before doing anything else.
My approach is to usually bump the version and go through each compilation error and check the release
notes for instructions on how to fix them.
Key points where I struggled:
- I initially just bumped the version of found that it couldn't find the `cats` module anymore
- I had to ask for help on gitter cause it wasn't able to make `mapN` (substitute of `|@|`) compile
because of SI-2712 fix missing
- when reading the documentation, more of us thought that `mapN` actually meant `map2`, `map3`,
`map4`, etc...maybe an explicit before/after example could help?

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
DanielaSfregola / perfomance-script.scala
Last active Mar 29, 2016
A quick and dirty experiment to compare the performance of scala immutable collections (Seq, List, Vector) of integers when accessing randomly, appending, prepending an element. See article
View perfomance-script.scala
import scala.concurrent.duration._
import scala.util.Random
import collection.immutable.Seq
private def prettyPrint(text: String)(duration: Duration): Unit =
println(s"[$text] - ${duration}")
private def ranges(base: Int, n: Int): Seq[Range] = for {
DanielaSfregola / MyConfig.scala
Last active Mar 20, 2022
A simple script that will try to load configurations in the following order: 1) From properly named environment variables 2) From command line paramenters 3) From the configuration file. See article
View MyConfig.scala
import com.typesafe.config.ConfigFactory
import scala.util.Properties
class MyConfig(fileNameOption: Option[String] = None) {
val config = fileNameOption.fold(
ifEmpty = ConfigFactory.load() )(
file => ConfigFactory.load(file) )
def envOrElseConfig(name: String): String = {
DanielaSfregola / demo-part1.scala
Last active Nov 22, 2015
Scala Italy 2015: An Introduction to Akka and the Actor-Based Model: Demo. See article
View demo-part1.scala
class SimpleActor extends Actor {
def receive = {
case msg => println(s"${self.path} - $msg")
View deadLettersChannelExample.scala
class EchoActor extends Actor {
def receive = {
case msg => println(s"${} - New msg received: $msg")
View customEventBusExample.scala
import akka.event.{LookupClassification, EventBus}
import akka.event.ActorEventBus
case class Book(title: String, authors: List[String])
class AuthorBookBus(author: String) extends EventBus
with LookupClassification
with ActorEventBus {
View eventStreamExample.scala
case class Book(title: String, authors: List[String])
class BookPublisher extends Actor {
def receive = {
case book: Book => {
println(s"Yeah! Publishing a new book: $book")