Skip to content

Instantly share code, notes, and snippets.

View filosganga's full-sized avatar

Filippo De Luca filosganga

View GitHub Profile
@johnynek
johnynek / flatMapFromTailRec.scala
Created October 7, 2017 01:55
I hadn't realized (maybe the original paper mentioned) but tailRecM + map is enough to do flatMap (and of course logically flatMap + pure are enough to do tailRecM).
object Monad {
trait Monad[F[_]] {
def pure[A](a: A): F[A]
/**
* We can have a default implementation in terms of tailRecM
* and map
*/
def flatMap[A, B](fa: F[A])(fn: A => F[B]): F[B] = {
def step(first: Option[A]): F[Either[Option[A], B]] =
@avakhrenev
avakhrenev / runConcat.scala
Last active January 22, 2019 14:35
fs2 runConcat. Evaluate two streams asynchronously, concating result.
import cats.effect.{Effect, IO}
import fs2._
import scala.concurrent.ExecutionContext
def runConcat[F[_], A](first: Stream[F, A], second: Stream[F, A])(
implicit F: Effect[F],
ec: ExecutionContext): Stream[F, A] = {
type Step = AsyncPull[F, Option[(Segment[A, Unit], Stream[F, A])]]
def readFull(s: Step): Pull[F, A, Unit] =
@klaaspieter
klaaspieter / ASS.md
Created June 22, 2017 07:59 — forked from anonymous/ASS.md
Acronyms Seriously Suck - Elon Musk

From time to time, Musk will send out an e-mail to the entire company to enforce a new policy or let them know about something that's bothering him. One of the more famous e-mails arrived in May 2010 with the subject line: Acronyms Seriously Suck:

There is a creeping tendency to use made up acronyms at SpaceX. Excessive use of made up acronyms is a significant impediment to communication and keeping communication good as we grow is incredibly important. Individually, a few acronyms here and there may not seem so bad, but if a thousand people are making these up, over time the result will be a huge glossary that we have to issue to new employees. No one can actually remember all these acronyms and people don't want to seem dumb in a meeting, so they just sit there in ignorance. This is particularly tough on new employees.

That needs to stop immediately or I will take drastic action - I have given enough warning over the years. Unless an acronym is approved by me, it should not enter the SpaceX glossary.

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 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

Explaining Miles's Magic

Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.

But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.

For starters, here is the sort of thing that SI-2712 affects:

def foo[F[_], A](fa: F[A]): String = fa.toString
@davidread
davidread / gist:0a34b59bffa86eb37812
Created December 11, 2015 20:53
Using Met Office weather open data on Azure Data Market
1. Register for Microsoft account at https://signup.live.com/signup
2. Email verification - click link (logs you in)
3. Register on Azure Data Market at https://datamarket.azure.com/register
4. Go to: https://datamarket.azure.com/dataset/datagovuk/metofficeweatheropendata click 'Sign up' then 'agree', then 'sign up'.
Use Web i/f to download CSV:
At: https://datamarket.azure.com/dataset/explore/0f2cba12-e5cf-4c6d-83c9-83114d44387a click 'Explore', 'Three Hourly Forecast' and 'Download Excel (CSV)'
or by API:
Go to: https://datamarket.azure.com/account for account key
@pcting
pcting / AkkaHttpCorsSupport.scala
Last active August 2, 2018 13:44
Akka HTTP 1.0 CORS Support
import akka.http.scaladsl.model.HttpHeader
import akka.http.scaladsl.model.HttpMethods._
import akka.http.scaladsl.model.HttpResponse
import akka.http.scaladsl.model.headers.`Access-Control-Allow-Credentials`
import akka.http.scaladsl.model.headers.`Access-Control-Allow-Methods`
import akka.http.scaladsl.model.headers.`Access-Control-Allow-Origin`
import akka.http.scaladsl.model.headers.Origin
import akka.http.scaladsl.server.Directive0
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.MethodRejection
@SethTisue
SethTisue / scalawags-33.md
Last active October 7, 2015 21:33
Scalawags #33: Back to School
@mpilquist
mpilquist / .gitignore
Last active August 29, 2015 14:27
Simulacrum Example
target