Skip to content

Instantly share code, notes, and snippets.

View raymondtay's full-sized avatar
🎯
Focusing

Raymond Tay raymondtay

🎯
Focusing
View GitHub Profile
import akka.actor._
import scala.concurrent._
import duration._
class EEcho extends Actor {
import ExecutionContext.Implicits.global
def receive = {
case Some(msg:Int) =>
println("RECV => " + msg)
package actors.scalaz
import scalaz._
import Scalaz._
import akka.actor._
import akka.util.Timeout
import akka.pattern.ask
import scala.concurrent._
import scala.concurrent.duration._
module Chapter26_1 where
import Control.Monad.Trans.Reader
import Data.Functor.Identity
-- Part (2) of my beginnings with Monad Transformers. See Part (1) of my journey with Monad Transformers written here (https://gist.github.com/raygit/e540aacf58e32d5e071d3d1cefb61b96)
--
-- I'm trying to understand how this would work. From the package's description
-- (https://hackage.haskell.org/package/transformers-0.5.2.0/docs/Control-Monad-Trans-Reader.html),
-- i see that:
{-# LANGUAGE InstanceSigs #-}
module Chapter26 where
import Control.Monad (liftM)
newtype MaybeT m a = MaybeT' { runMaybeT :: m (Maybe a) }
instance (Functor m) => Functor (MaybeT m) where
fmap f (MaybeT' ma) = MaybeT' $ (fmap . fmap) f ma
import scalaz._
import Scalaz._
case class Result(eCode: Int)
case class Action(z: Int, f : Int => Int)
// Artificially created two "steps" with the intention
// combining them later in a composition
val step1 = State[Action, Result] {
case (a: Action) =>
template<int v>
struct Int2Type {
enum { value = v };
};
import java.util.*;
interface Fn<T,R> {
R apply(T a);
R f(T a);
}
// Created for the purpose of a class.
class AddOneFunction implements Fn<Integer,Integer> {
public Integer apply(Integer a) { return f(a); }
@raymondtay
raymondtay / .vimrc
Last active December 16, 2015 07:49
my vimrc
set t_Co=256
set nu
set hlsearch
syntax on
set tabstop=4
set background=dark
let g:solarized_termcolors=256
colorscheme solarized
set shiftwidth=4
set expandtab
@raymondtay
raymondtay / user2.scala
Last active December 14, 2015 11:39
Version 2 with type-level programming
import java.util.concurrent.locks._
// Doesn't appear to make sense to create an abstraction
// to allow users to receive the status of the acquiring or
// releasing a lock over an object because ...
//
trait LockStrategy[L <: Lock] {
protected val lck : Lock = null
def lock : Unit
def unlock : Unit
@raymondtay
raymondtay / user1.scala
Created March 4, 2013 07:14
version with self-types
import java.util.concurrent.locks._
trait LockStrategy[L <: Lock] {
protected val lck : Lock = null
def lock : Unit
def unlock : Unit
}
trait AllowReentrancy extends LockStrategy[ReentrantLock] {
override val lck = new ReentrantLock