Tonight I tried to run this code:
broadcast.transcriptions
.sort! { |transcription| transcription.created_at.to_unix }
.last
broadcast and transcription are Avram model instances, and created_at is a Time.
I was at first surprised that crystal’s Array#sort doesn’t know how to compare Time, but I jumped to #to_unix thinking that’d be an easy escape. Unfortunately, this cryptic reaper (still) popped out of the compiler:
Error target worker failed to compile:
In /Users/robert/.asdf/installs/crystal/1.11.2/src/array.cr:1661:10
1661 | {% raise "Expected block to return Int32 or Nil, not #{U}" %}
^----
Error: Expected block to return Int32 or Nil, not Int64
Brutal! Both a dead end, and a cryptic error message
Is there a way to trick the sorting algorithm to sort by something like Time, which is quite sortable if you know what you’re doing?