This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'singleton' | |
class Maybe | |
def self.unit(value) | |
if value.nil? || (value.respond_to?(:empty?) && value.empty?) | |
Nothing.instance | |
else | |
Just.new(value) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def self.unit(value) | |
[value] | |
end | |
def bind(&block) | |
flat_map(&block) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Identity | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end | |
private_class_method :new | |
def self.unit(value) | |
new(value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Monoid | |
-- Max: Monoid of Num under max. | |
data Max a = Max a | MinInfinity deriving Show | |
instance (Num a, Ord a) => Monoid (Max a) where | |
mempty = MinInfinity | |
MinInfinity `mappend` m = m | |
m `mappend` MinInfinity = m | |
Max x `mappend` Max y = Max (Prelude.max x y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p id="notice"><%= notice %></p> | |
<h1>Listing Tweets</h1> | |
<section id="tweets"> | |
<% @tweets.each do |tweet| %> | |
<article class="tweet"> | |
<p>@<%= tweet.user.username %></p> | |
<p><%= tweet.body %></p> | |
<p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Bot do | |
@commands = %{"a" => :do_a, "b" => :do_b} | |
def match(command) do | |
execute(@commands[command]) | |
end | |
def execute(:do_a) do | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$global_value = 0 | |
def rq(x) | |
$global_value = $global_value + 1 | |
x + $global_value | |
end | |
def rt(x) | |
x + 1 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def average_age | |
return 0 if @group.empty? | |
sum = @group.map{|x| x.age} | |
.reduce(0.0){|sum, x| sum + x} | |
sum / @group.size | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/src/app % mix deps.get && mix test | |
* Updating rabbit_common (git://github.com/jbrisbin/rabbit_common.git) | |
Running dependency resolution | |
Dependency resolution completed successfully | |
rabbit_common: v3.4.0 | |
Unchecked dependencies for environment test: | |
* rabbit_common (git://github.com/jbrisbin/rabbit_common.git) | |
lock outdated: the lock is outdated compared to the options in your mixfile | |
** (Mix) Can't continue due to errors on dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cities_in_region(region_id) | |
Regions.lookup(region_id) | |
.or(Left("Couldn't find region #{region_id}")) | |
>-> region { region.bounding_box } | |
.or(Left("Region #{region_id} has no bounding box")) | |
>-> bounding_box { GeoNames.search_cities(bounding_box) } | |
end |