I wrote a library tallboy to generate text based tables a while ago to learn Crystal.
Recently I rewrote it and Initially I was looking for golang like interfaces but in Crystal you have to explicitly include modules as interfaces.
Later I found that Crystal has structural typing and it does 90% of what I wanted but I am unsure the following.
# say I have an array of integers arr = [1, 2, 3] # and and class Group which holds an array of integers or strings class Group def initialize(@items : Array(Int32 | String) end end # I can't just pass the array in Group.new(arr) # I have to first type cast each element Group.new(arr.map(&.as(Int32 | String)))
.as the best approach here and does anyone actually define modules as interfaces? I found using modules it’s cumbersome to cast back and forth.
and if you checked out the library any feedback at all I would love to hear it.