Skip to content

Instantly share code, notes, and snippets.

Daniela Sfregola DanielaSfregola

Block or report user

Report or block DanielaSfregola

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
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
DanielaSfregola / Applicative.scala
Last active Jun 24, 2018
tutorial-cat-solutions
View Applicative.scala
package com.danielasfregola.tutorial.cat.applicative
import com.danielasfregola.tutorial.cat.functor.Functor
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?
View Advanced-FP-with-Scala.md

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
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 http://danielasfregola.com/2015/06/15/which-immutable-scala-collection.
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
DanielaSfregola / MyConfig.scala
Last active Feb 10, 2018
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 http://danielasfregola.com/2015/06/01/loading-configurations-in-scala/
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
DanielaSfregola / demo-part1.scala
Last active Nov 22, 2015
Scala Italy 2015: An Introduction to Akka and the Actor-Based Model: Demo. See article http://danielasfregola.com/2015/05/11/scala-italy-2015-highlights/
View demo-part1.scala
import akka.actor._
class SimpleActor extends Actor {
def receive = {
case msg => println(s"${self.path} - $msg")
}
}
View deadLettersChannelExample.scala
import akka.actor._
class EchoActor extends Actor {
def receive = {
case msg => println(s"${self.path.name} - New msg received: $msg")
}
}
View customEventBusExample.scala
import akka.actor._
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
import akka.actor._
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")
context.system.eventStream.publish(book)
You can’t perform that action at this time.