September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -0,0 +1,23 @@
class Apple
def eat
end
end
class Carrot
def eat
end
end
class FoodBox(T)
def initialize(@data : Array(T))
{% if T.union? %}
{% raise "All items should be eatable" unless T.union_types.all? &.has_method?(:eat) %}
{% else %}
{% raise "Items should be eatable" unless T.has_method?(:eat) %}
{% end %}
end
end
FoodBox.new([Apple.new, Apple.new])
FoodBox.new([Apple.new, Carrot.new])
FoodBox.new([Apple.new, Carrot.new, 123])

View file

@ -0,0 +1,21 @@
use Collection.Generic;
interface Eatable {
method : virtual : Eat() ~ Nil;
}
class FoodBox<T : Eatable> {
food : List<T>;
}
class Plum implements Eatable {
method : Eat() ~ Nil {
"Yummy Plum!"->PrintLine();
}
}
class Genericity {
function : Main(args : String[]) ~ Nil {
plums : FoodBox<Plum>;
}
}