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 'rspec' | |
class Object | |
def peg(&block) | |
block.call(self) | |
end | |
def wend(arg) | |
Wender.new(self, arg) |
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
(defun restart-sml () | |
(sml-prog-proc-switch-to) | |
(end-of-buffer) | |
(comint-delchar-or-maybe-eof 0)) | |
(defun run-sml-tests-now () | |
(let* ((code-file-name | |
(replace-regexp-in-string "_tests" "" (buffer-file-name))) | |
(test-file-name | |
(replace-regexp-in-string "\.sml" "_tests.sml" code-file-name))) |
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
"Nils - what are your Options?" - Russell Dunphy | |
Tony Hoare, inventor of the null reference, calls it his "billion dollar mistake". | |
Although Ruby goes some way to correcting it by making `nil` at least be a class | |
with some reasonably helpful stuff on it, you'll no doubt have been hit by a | |
`NoMethodError: undefined method 'foo'` just as many times as me. | |
So, given this problem exists, I want to convince you of a few things. | |
First, that there are not one, but two types of `nil`. |
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
## Model code | |
class Customer < ActiveRecord::Base | |
def find_by_name(name) | |
Option[where(name: name).first] | |
end | |
end | |
## Controller code |
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
-module(infinite). | |
-compile(export_all). | |
%%% Usage | |
% | |
% Ints = infinite:stream(0, fun (X) -> X + 1 end). | |
% | |
% % Numbers from 0 to 9 | |
% infinite:take(Ints, 10). | |
% |
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
class DCode | |
def initialize(assessment, user) | |
@assessment = assessment | |
@user = user | |
end | |
def code | |
"#{site.name[0,2]}-#{department_code}".upcase | |
end |
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
normal score: 41 (4 then 1) | |
spare: 3/ | |
strike: X | |
score then gutter: 4- | |
34X--3/34 |
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
## Making Option[[]], Option[{}] and Option[""] return None | |
Looked at a certain way, it does make a kind of sense. I can see how you got the idea. | |
A None is itself a kind of empty collection, so why wouldn't an Option of an empty collection also be a None? | |
However, I think there are some important things we need to consider. | |
The first one is - why would you be creating an optional collection - what value would you be getting from doing so? | |
And what value would you be getting from empty collections being interpreted as None? |
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
module Main where | |
import System.Environment | |
main :: IO () | |
main = do | |
args <- getArgs | |
mapM_ putStrLn $ sort args | |
sort :: (Ord a) => [a] -> [a] |
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
module Main where | |
import System.Environment | |
main :: IO () | |
main = do | |
args <- getArgs | |
mapM_ putStrLn $ sort args | |
sort :: (Ord a) => [a] -> [a] |
OlderNewer