Skip to content

Instantly share code, notes, and snippets.

View missingfaktor's full-sized avatar
🥔

Rahul Goma Phulore missingfaktor

🥔
View GitHub Profile
@milessabin
milessabin / gist:2500326
Created April 26, 2012 15:22
Scala collection extension methods made easy (dependent types FTW!)
/*
* Copyright (c) 2012 Miles Sabin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@etorreborre
etorreborre / gist:2231981
Created March 29, 2012 00:55
Using Scalaz to get the applicative syntax for ScalaCheck generators
import scalaz.Apply
import org.scalacheck.Gen
import org.scalacheck.Arbitrary._
/**
* Use this trait to get applicative syntax when building generators. This
* is especially useful when building generators for case classes.
*
*/
trait Data {
@tsabat
tsabat / zsh.md
Last active June 30, 2026 15:31
Getting oh-my-zsh to work in Ubuntu
@retronym
retronym / config.scala
Last active May 9, 2018 05:47
Styles of config propagation: Manual, Implicits, DynamicVariable, Reader
package scalaz.example
object Reader extends App {
/**
* Manual propagation of the environment (in the example, `contextRoot`.)
*/
object Config0 {
def fragment1(contextRoot: String) = <a href={contextRoot + "/foo"}>foo</a>
def unexpected : Nothing = sys.error("Unexpected invocation")
// Encoding for "A is not a subtype of B"
trait <:!<[A, B]
// Uses ambiguity to rule out the cases we're trying to exclude
implicit def nsub[A, B] : A <:!< B = null
implicit def nsubAmbig1[A, B >: A] : A <:!< B = unexpected
implicit def nsubAmbig2[A, B >: A] : A <:!< B = unexpected
@missingfaktor
missingfaktor / ExperimentingWithIo.scala
Created September 10, 2011 13:53
Playing with Scalaz effects
import scalaz._
import Scalaz._
import effects._
object ExperimentingWithIo {
def main(args: Array[String]): Unit = {
val i1: IO[Unit] = for {
_ <- putStrLn("What's your name?")
@retronym
retronym / Coder.scala
Created August 20, 2011 07:25
Martin Odersky's Phone Coder example
package demo
class Coder(words: List[String]) {
private val mnemonics = Map(
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL",
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ")
/** Invert the mnemonics map to give a map from chars 'A' ... 'Z' to '2' ... '9' */
private val charCode: Map[Char, Char] =
@krasserm
krasserm / MonadTransformerExamples.scala
Created July 14, 2011 10:32
Scalaz 7 monad transformer examples
import scalaz._
import Scalaz._
object MonadTransformerExamples {
def main(args: Array[String]) = run
def run {
// ------------------------------------------------------
// Combined Option/Option
// ------------------------------------------------------
@debasishg
debasishg / gist:1059864
Created July 2, 2011 08:37
Tony Morris' Option using catamorphism
trait MyOption[+A] {
// single abstract method
def cata[X](some: A => X, none: => X): X
import MyOption._
def map[B](f: A => B): MyOption[B] = cata(f andThen some, none)
// Also
// def map[B](f: A => B): MyOption[B] = flatMap(f andThen some)
@viktorklang
viktorklang / ScalaEnum.scala
Created June 30, 2011 23:12
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get