Skip to content

Instantly share code, notes, and snippets.

@SteveBate
SteveBate / PipeAndFilters.scala
Created October 9, 2013 13:56
A basic Scala implementation of the messaging pipeline as described at http://eventuallyconsistent.net/2013/08/12/messaging-as-a-programming-model-part-1/
import scala.collection.mutable.ListBuffer
val msg1 = new Network1(1);
val msg2 = new Network1(2);
val msg3 = new Network1(3);
val pipeline = new PipeLine[Network1]();
pipeline.register((x: Network1) => new GetUndeliveredOrders(x))
.register((x: Network1) => new GetDeliveryInfo(x))
.register((x: Network1) => new GetPodImage(x))
@SteveBate
SteveBate / PipeAndFilters.js
Last active December 25, 2015 02:19
A basic Javascript implementation of the messaging pipeline as described at http://eventuallyconsistent.net/2013/08/12/messaging-as-a-programming-model-part-1/
var utils = utils || {};
// pipeline
utils.pipeline = function(){
var handlers = [];
var register = function(handler){
if(typeof handler !== 'function')
throw { name: 'InvalidTypeException', description: 'handler should be a function'}
@SteveBate
SteveBate / ArrayExercise.js
Created October 9, 2013 13:36
Exercise testing the various Javascript Array methods but particularly the functional methods available
// set up arrays
var numbers = [1,12,4,18,9,7,11,3,101,5,6];
var strings = ['this','is','a','collection','of','words'];
// array.reduce - find largest number
var largestValue = numbers.reduce(function(x,y){ return x > y ? x : y });
console.log('largest number: ' + largestValue);
// array.reduce - find longest string
@SteveBate
SteveBate / Functions.js
Last active December 23, 2015 21:19
A Javascript exercise to create a revealing module that exposes linq-style functional operators such as map, reduce, filter and others. Note that most of these operations are available on the Array class anyway.
var utils = utils || {};
utils.linq = function(){
range = function(start, end){
var numbers = [];
for(var x=start; x<=end;x++)
numbers.push(x);
return numbers;
}