Skip to content

Instantly share code, notes, and snippets.

@theotherzach
Last active August 29, 2015 13:56
Show Gist options
  • Save theotherzach/9246008 to your computer and use it in GitHub Desktop.
Save theotherzach/9246008 to your computer and use it in GitHub Desktop.
def game ->
[] >> game
def game rolls ->
def scoreIter array -> (score)
length == 0
score >> return
if [0] == 10 # sugar for >> { [0] == 10 }()
slice(1)
scoreIter((+ score 10 array[1] array[2]))
if [0] + [1] == 10
slice(2)
scoreIter((+ score 10 array[2]))
else
slice(2)
scoreIter((+ score array[0] array[1]))
return << {
def roll pins ->
rolls >> concat(pins)
game()
def score ->
rolls >> scoreIter(0)
}
@theotherzach
Copy link
Author

entry :current_user do  |:session, :params|
  #=> <Session:0x007ffc3a89c5b8>
  Sequel.find(:session, table: "users")
  #=> <SequelRow: {table:"users", @attributes: {id: 24, name: "Bob"}}>
  User.hydrate :row
  #=> <User: {id: 24, name: "Bob"}>
  if Devise.invalid_user? { next(null, :params) }
  #=> <User: {id: 24, name: "Bob"}>
  next(:current_user, *args)
  #=> invoked <Entry: {:post, :documents} >, <User: {id: 24, name: "Bob"}>, <Params: {body:"stuff",pub_date:"2015/08/28"}>
end

entry :post, :documents do |:params, :current_user|
  #=> <Params: {body:"stuff",pub_date:"2015/08/28"}>
  Document.hydrate(:params, :current_user)
  #=> <Document: {id:0x007ffc3a153d60, body:"stuff", pub_date:"2015/08/28", user: ...}>
  if Publisher.document_hold? DocumentWorker.schedule
  #=> <Document: {id:0x007ffc3a153d60, scheduled?: true, body:"stuff", pub_date:"2015/08/28", user: ...}>
  try { Sequel.insert :row, table: "documents" } catch { next  }
  #=> <Document: {id:0x007ffc3a153d60, body:"stuff", pub_date:"2015/08/28", user: ...}>
  next(:params, success: true)
  #=> invoked <Exit: {:params, :success} >, <Document: {id:0x007ffc3a153d60, body:"stuff", pub_date:"2015/08/28", user: ...}>
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment