Skip to content

Instantly share code, notes, and snippets.

View j1n3l0's full-sized avatar

Nelo Onyiah j1n3l0

  • Goznel Limited
  • Kent UK
  • 23:34 (UTC -12:00)
View GitHub Profile
@j1n3l0
j1n3l0 / TypeclassDemo.scala
Created October 7, 2015 10:03 — forked from davegurnell/TypeclassDemo.scala
Example of the type class pattern in Scala
object TypeclasseDemo {
// The parts of the type class pattern are:
//
// 1. the "type class" itself -- a trait with a single type parameter;
//
// 2. type class "instances" for each type we care about,
// each marked with the `implicit` keyword;
//
// 3. an "interface" to the type class -- one or more methods
(defn parse-flags
"Parse a list of flags. Each flag name must be a keyword, and the
value must not be a keyword. If the value is omitted, true is
assumed. Returns a map.
e.g. (parse-flags [:i :j 1 :k \"two\"])
=> {:i true, :j 1, :k \"two\"}"
[flags]
(loop [flags (seq flags) accum {}]
(if flags
;; Perl: $RE{num}{-base => 2}{real}{-group => 3}{-sep => ','}
(re-seq (re :real {:base 2 :group 3 :sep \,} ) "1.345")
#! /usr/bin/env ruby
# Author:: Sébastien Briois (sebriois@gmail.com)
require "rubygems"
require "rest_client"
require "json"
IDCC_SITE = "http://user:pass@localhost:3000"