This file contains hidden or 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
| (ns run-length-encoding) | |
| ;; Combinators | |
| (defn matches [predicate] | |
| (fn [input] | |
| (if (not (empty? input)) | |
| (let [[head & tail] input] | |
| (if (predicate head) [head (apply str tail)]))))) | |
| (defn mmap [func parser] |
This file contains hidden or 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
| fn main() { | |
| println!("Hello, world!"); | |
| } |
This file contains hidden or 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
| // Consumes value, returns nothing (cannot be assigned) | |
| fn eat_it(c: Cake) {} | |
| // Consumes value, returns another **different** value | |
| fn recycle(c: Cake) -> Cake {} | |
| // Reads value. Nothing more. | |
| fn look_at(c: &Cake) {} | |
| // Changes the cake we pass into it. |
This file contains hidden or 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
| begin | |
| require 'bundler/inline' | |
| rescue LoadError => e | |
| $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
| raise e | |
| end | |
| gemfile(true) do | |
| source 'https://rubygems.org' | |
| gem 'rails', '5.1.0' # use correct rails version |
This file contains hidden or 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 'active_support/inflector' | |
| require 'benchmark' | |
| class James | |
| end | |
| class John | |
| end | |
| class Jimmy |
This file contains hidden or 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
| enum = Enumerator.new do |yielder| | |
| n = 0 | |
| loop do | |
| yielder << n | |
| n += 1 | |
| end | |
| end | |
| # Take creates a new Array | |
| enum.take(10) #=> [0,1,2,3,4,5,6,7,8,9] |