Created
October 10, 2011 13:35
-
-
Save igravious/1275345 to your computer and use it in GitHub Desktop.
Recursive lazy evaluated URLs
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 'rubygems' | |
require 'camping' | |
require 'lazy' | |
class Endless | |
include Enumerable | |
def initialize | |
make_a_promise Lazy.promise &Proc.new | |
end | |
def make_a_promise(p) | |
@p = p | |
end | |
def get_promise | |
@p | |
end | |
def each | |
p = get_promise | |
a = [] | |
while p | |
car, cdr = p | |
head_by_tail = car[1] | |
a << head_by_tail | |
yield head_by_tail | |
p = cdr.get_promise | |
end | |
a | |
end | |
def map | |
p = get_promise | |
a = [] | |
while p | |
car, cdr = p | |
head_by_tail = car[1] | |
a << (yield head_by_tail) | |
p = cdr.get_promise | |
end | |
a | |
end | |
end | |
def endless_path(head, tail) | |
Endless.new { [[tail, head * tail], endless_path(head, tail+1)] } | |
end | |
Camping.goes :WowJustWow | |
module WowJustWow | |
end | |
module WowJustWow::Controllers | |
class Index | |
def get | |
"/" | |
end | |
end | |
class Dyn < R() | |
def self.urls | |
endless_path("/([^/]+)",1) | |
end | |
def get(first, *rest) | |
"#{first} #{rest}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment