monads are an abstraction
objects are an abstraction
They're two very different abstractions :-)
In my opinion, monads are much simpler than objects.
Because monads are only abstractions of structure, where you get to change the meaning yourself. >
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 AssignCaseCommand < Command | |
attribute :case, Case | |
attribute :owner, User | |
attribute :created_by, User | |
attribute :comments, String | |
attribute :distribute_at, DateTime | |
attribute :distribute_rule_name, String | |
attribute :require_initial, Boolean |
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
# MODEL | |
class Case < ActiveRecord::Base | |
include Eventable | |
has_many :tasks | |
concerning :Assignment do | |
def assign_to(new_owner:, details:) | |
transaction do |
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 get_rstring(addr): | |
s = addr.cast(string_t.pointer()) | |
if s['basic']['flags'] & (1 << 13): | |
return s['as']['heap']['ptr'].string() | |
else: | |
return s['as']['ary'].string() | |
def get_lineno(iseq, pos): | |
if pos != 0: | |
pos -= 1 |
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
# make this script run, update your gist with the running script, and it's | |
# output in a separate gist. the entire quzi should take 1-3 minutes, but you | |
# get 5. | |
# | |
# the meat - take < 5 minutes to do this | |
# | |
assert :hash do | |
x = x.to_h |
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
# fyi: I have no idea what I'm doing :) | |
Log = Struct.new :buffer do | |
def call method | |
buffer << "Log: before #{method.name}\n" | |
method.call buffer | |
buffer << "Log: after #{method.name}\n\n" | |
self | |
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
puts "toplevel Module nesting: #{Module.nesting.inspect}" | |
class Foo | |
def bar | |
puts "hello from Foo#bar" | |
end | |
end | |
::ExportedFoo = Foo |
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
I = -> x { x } | |
C = -> x { -> y { -> z { x[z][y] } } } | |
T = -> C[I] | |
K = -> x { -> y { x } } | |
U = -> f { f[f] } | |
# I know, this technically isn't the Y combinator, | |
# and it isn't exactly the Z combinator either (like Y, but for applicative order languages). | |
Y = -> g { U[-> f { -> x { g[U[f]][x] } } ] } | |
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
-- Exercise 1 | |
-- converts positive Integers to a list of digits. | |
toDigits :: Integer -> [Integer] | |
toDigits x = reverse (toDigitsRev x) | |
toDigitsRev :: Integer -> [Integer] | |
toDigitsRev x | |
| x <= 0 = [] | |
| otherwise = (mod x 10) : toDigitsRev (div x 10) |
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 enum blk = Proc.new | |
m = Module.new | |
o = Object.new | |
o.instance_eval { | |
@enum_idx = -1 | |
@enum_mod = m | |
def method_missing(n, *a) | |
n =~ /([A-Z][A-Z_]*)(=)?/ | |
raise "bad enum name #{n}" unless $1 | |
if $2 |
OlderNewer