Skip to content

Instantly share code, notes, and snippets.

View channingwalton's full-sized avatar
🏠
Working from home

Channing Walton channingwalton

🏠
Working from home
View GitHub Profile
@gabydd
gabydd / config.toml
Last active May 8, 2024 11:07
helix lf
[keys.normal]
C-f = [":new", ":insert-output lf-pick", "split_selection_on_newline", "goto_file", "goto_last_modification", "goto_last_modified_file", ":buffer-close!", ":theme nord", ":theme default"]
# replace the default after theme with the theme you use
# open 1 with the open command (l and <left> to open) or more with (<space> to select) then quit
# all opened files will be opened in helix

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
@milessabin
milessabin / gist:25b7b669b5a9ac051a71
Created June 5, 2015 14:32
A safe ADT+shapeless drop-in replacement for the unsafe standard Scala Enumeration ...
// An ADT+shapeless as a drop-in replacement for a standard Scala Enumeration.
//
// First the unsafe standard Scala Enumeration ...
//
object ScalaEnumDemo extends App {
// Example from scala.Enumeration scaladoc. Terse ...
object WeekDay extends Enumeration {
type WeekDay = Value
val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
}
@paf31
paf31 / 24days.md
Last active August 8, 2023 05:53
24 Days of PureScript

This blog post series has moved here.

You might also be interested in the 2016 version.

@runarorama
runarorama / gist:a8fab38e473fafa0921d
Last active April 13, 2021 22:28
Compositional application architecture with reasonably priced monads
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]
@mattdenner
mattdenner / gist:4977805
Created February 18, 2013 14:28
Me attempting to get my head around monads.

My biggest problem with monads is that my brain can't grasp them, obviously! One of the issues I've got is that people teach them as part of a somewhat bigger context: they start showing how Option[T] works and then suddenly declare ''Option[T] is a monad''! Or worse, they talk about something completely unrelated in an attempt to give you some real world perspective onto them. It's not working for me and it might not be working for you; what I'll write here is to help me understand monads, and it probably won't work for you, but it might.

I'm going to start with an extremely simple case class and build it up from there:

final case class Holder[+T](value: T)

It's really simple in that it holds a value of a type T. One thing to realise is that case class in Scala automatically gives you a companion object for Holder[T] called Holder which gives you an apply method for creating instances. I'm going to make a similar object, which I'll abitrarily call HolderMonad, that will have

@przemek-pokrywka
przemek-pokrywka / ReaderMonadDIWhenFunsDependOnVariousThings.scala
Created January 21, 2013 22:46
Reader Monad dependency injection when each of injected functions depends on something other. The goal is to assess, how good does Reader Monad fit into this context.
case class Reader[Conf, Res](obtainResult: Conf => Res) {
def map[NewRes](transform: Res => NewRes) =
Reader {
(config: Conf) =>
transform(this obtainResult config)
}
def flatMap[NewRes](createReader: Res => Reader[Conf, NewRes]) =
Reader {
@stew
stew / kleisliexample.scala
Created January 16, 2013 14:07
example of kleisli in kleisli
import scalaz._
import Scalaz._
case class Person(name: String, score: Int)
object Main extends App {
type Environment = Map[String, Person]
type EnvReader[+A] = Kleisli[Option,Environment,A]
type UserReader[+A] = Kleisli[EnvReader,String,A]
@chrislewis
chrislewis / gist:4409778
Created December 29, 2012 22:45
A Reader Either monad transformer for java.util.Properties with Scalaz7
/*
* This is a rendition of https://gist.github.com/3416494. Scalaz7 provides the
* Reader and we take it a step further by constructing and using a Reader Either
* monad transformer with pure error handling, instead of the original impure Reader
* monad that would throw exceptions on parse errors.
*/
import scalaz._
import Scalaz._
import java.util.Properties
@etorreborre
etorreborre / gist:4187596
Created December 2, 2012 07:27
Monoids for the option of a function
import scalaz._
import Scalaz._
trait A {
def increment: A
}
case class A1(i: Int) extends A {
def increment = A1(i+20)
}