Skip to content

Instantly share code, notes, and snippets.

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

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
@jdegoes
jdegoes / HigherKindedJava.java
Last active January 9, 2019 11:23
Modeling higher-kinded types in a language without them.
class Option<A> {
protected Option() { }
}
interface App<F, A> {
F proof();
}
class OptionF {
private OptionF() {}
private static class AppOption<A> implements App<OptionF, A> {
@sjoerdvisscher
sjoerdvisscher / expression-problem.swift
Last active August 21, 2019 16:57
Finally tagless in Swift 3
protocol Expr {
static func lit(_ x: Int) -> Self
static func add(_ lhs: Self, _ rhs: Self) -> Self
}
extension Int : Expr {
static func lit(_ x : Int) -> Int {
return x;
}
static func add(_ lhs: Int, _ rhs: Int) -> Int {

Take-home functional programming interview

This document is licensed CC0.

These are some questions to give a sense of what you know about FP. This is more of a gauge of what you know, it's not necessarily expected that a single person will breeze through all questions. For each question, give your answer if you know it, say how long it took you, and say whether it was 'trivial', 'easy', 'medium', 'hard', or 'I don't know'. Give your answers in Haskell for the questions that involve code.

Please be honest, as the interviewer may do some spot checking with similar questions. It's not going to look good if you report a question as being 'trivial' but a similar question completely stumps you.

Here's a bit more guidance on how to use these labels:

@gneuvill
gneuvill / Free.java
Last active October 24, 2016 19:59
@Data(flavour = Flavour.FJ)
public abstract class Free<f, A> implements __2<Free.µ, f, A> {
Free() {}
interface Cases<f, A, R> {
R Return(A a);
R Suspend(__<f, A> fa);
R Gosub(Sub<f, A, ?> sub);
}
abstract <R> R match(Cases<f, A, R> cases);
@jdegoes
jdegoes / lambdaconf-sums-products.md
Created March 17, 2016 19:01
Exercises for "Sums and Products, Oh My!" — LambdaConf Outpost One Meetup (3/17/2016)

Introduction

A type is a set of values.

Int -- The set of all integer values (that fit into 64 bits)

To say that a term a has type A is to say that a is a member of the set of values represented by A.

@CMCDragonkai
CMCDragonkai / short_circuiting_fold.md
Created February 5, 2016 09:10
Haskell: Short Circuiting Fold (Simulating Break in Imperative Languages)

Short Circuiting Fold

This pretty much explains it: http://crypto.stanford.edu/~blynn/haskell/foldl.html here I just review the article.

The rule of thumb is this:

  • if you want short circuiting on foldr, use a lazy on the right combiner
  • if you want short circuiting on foldl, use a lazy on the left combiner
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import Prelude hiding (log)
--------------------------------------------------------------------------------
-- The API for cloud files.
class Monad m => MonadCloud m where
saveFile :: Path -> Bytes -> m ()
@3noch
3noch / install-ghcjs-for-stack.hs
Last active August 28, 2016 12:48
Install GHCJS for Stack
#!/usr/bin/env stack
-- stack --install-ghc runghc --package turtle --package wreq
{-# LANGUAGE OverloadedStrings #-}
import qualified Control.Foldl as Fold
import Control.Lens ((^.))
import Control.Monad (when)
import Data.ByteString.Lazy (hPut)
import Data.Maybe (fromMaybe)