Skip to content

Instantly share code, notes, and snippets.

@pierangeloc
pierangeloc / ScalaX-2017-day-1.md
Last active December 15, 2017 08:37
ScalaX-2017-day-1

ScalaX 2017

Bartosz Milewski: Cat theory

Cat Theory: science of composition. Most of maths can be based on it, and programming as well.

Compose and abstract. We need to abstract because we can't hold more than 2-3 things and details at time in our head (short memory). We can't check every time the impl details.

FP

f: A => B. Can either base on Set theory, or forget about details and focus on substance, and I have object/arrows and properties.

Advanced Functional Programming with Scala - Notes

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

Dependent Typing (@Nick_enGB, @nstack)

(Algebraic Infrastructure company) ==> Major takeaway: Why DT matters

  • Express types that couldn't express otherwise Type system is to prove something about our program, through syntactical rules. So we prove things @ compile time. Typically we think of type in terms of how they look like on the memory structure. But type is more about guaranteeing behavior. E.g. a NEL has same shape as List, but gives one extra guarantee!

Aim: prove properties through type system (Curry-Howard): types are propositions (statements), and values are proofs of those proposition. Functions? Are implications: If input is A, output is of type B => it's a way where inputs are preconditions, outputs are postconditions.

Ammonite for Scala Scripting (@li_haoyi)

can do amm foo.sc, but also scala foo.sc. So why use it? Because I can import dependency on the fly. With scala I have to use -cp ... => Blah! And I can't import other scripts

####amm scripting

import $file.foo.bar` //import ./foo/bar.sc
foo.bar.methodOfBar(argument)
@pierangeloc
pierangeloc / scala-intro-devjam.scala
Created March 22, 2016 22:08
REPL after the Gentle Scala Introduction @ Sytac DevJam
/**
* For the first part I had to rely on the repl history as the console buffer was gone after the stack overflow of factorial
*/
val i = 10
:type i
val i: Int = 10
val s = "Ciao"
i = 4
var j = 20
j = 10

##Shapeless

Type class derivation: applies to ADT(Alg Data Types). ADT is a sealed _empty_trait extended by case classes. Many advantages

Type class: trait indexed on a type T and provides some methods and defs on the type T. in the comp obj we define a def of the typed class for that type, and we can derive it through the implicitly

trait Eq[T] {
	def eqv(x: T, y: T): Boolean
}
@pierangeloc
pierangeloc / mongo-db-queries.js
Last active December 30, 2015 21:39
mongoDB queries compendium. This is an overview of the capabilities of Mongo that I have been using during the M101J course
//find from people collection
// _id can be not only a scalar value but also a document:
db.people.insert({_id: {"bsn": "2322323", "phone_nr" : "0612313123123"}})
/** QUERIES **/
// find documents where profession exists
db.people.find({profession: {$exists: true}})
// find documents where name attribute has type String (for the correspondence between String and type
//number, refer to http://bsonspec.org/#/specification)