diff --git a/crystal/README.md b/crystal/README.md index c02ebe86b..1e81d8afd 100644 --- a/crystal/README.md +++ b/crystal/README.md @@ -20,7 +20,10 @@ ## Ideas for slides -I run +The need to recompile the whole thing before I run it and the fact that compilation is slow makes life of a (web) developer hard. +The Jinja Template system of Johannes that does not need to be compiled makes at least the HTML development much faster. + +I run crystal example.cr I get Showing last frame. Use --error-trace for full trace. diff --git a/crystal/arrays.md b/crystal/arrays.md index 5a974ae12..49d02f1e0 100644 --- a/crystal/arrays.md +++ b/crystal/arrays.md @@ -118,3 +118,16 @@ {id: arrays-join} ![](examples/arrays/join.cr) + +## Remove nil elements +{id: remove-nil-elements} +{i: compact} + +![](examples/arrays/remove_nils.cr) + +## Create Array with nil +{id: array-with-nil} +{i: 0_i64} + +![](examples/arrays/array_with_nil.cr) + diff --git a/crystal/examples/arrays/array_with_nil.cr b/crystal/examples/arrays/array_with_nil.cr new file mode 100644 index 000000000..3e95dcd26 --- /dev/null +++ b/crystal/examples/arrays/array_with_nil.cr @@ -0,0 +1,6 @@ +n = 5 +nums = (0_i64.as(Int64 | Nil)..n).to_a +puts typeof(nums) # Array(Int64 | Nil) + +other = [nil] + (1..n).to_a +puts typeof(other) # Array(Int32 | Nil) diff --git a/crystal/examples/arrays/remove_nils.cr b/crystal/examples/arrays/remove_nils.cr new file mode 100644 index 000000000..19dc41781 --- /dev/null +++ b/crystal/examples/arrays/remove_nils.cr @@ -0,0 +1,7 @@ +numbers = [nil, 2, 3, nil, nil, 7, nil] +puts numbers +puts numbers.compact +puts numbers + +puts numbers.compact! +puts numbers diff --git a/crystal/examples/int64_zero.cr b/crystal/examples/int64_zero.cr new file mode 100644 index 000000000..5c1c84201 --- /dev/null +++ b/crystal/examples/int64_zero.cr @@ -0,0 +1,4 @@ +zero = 0_i64 + +p! zero +p! typeof(zero) diff --git a/crystal/examples/range/to_a.cr b/crystal/examples/range/to_a.cr new file mode 100644 index 000000000..5328e456c --- /dev/null +++ b/crystal/examples/range/to_a.cr @@ -0,0 +1,3 @@ +numbers = (2..7).to_a +p! typeof(numbers) +p! numbers diff --git a/crystal/examples/range/to_a.out b/crystal/examples/range/to_a.out new file mode 100644 index 000000000..d1c275b2f --- /dev/null +++ b/crystal/examples/range/to_a.out @@ -0,0 +1,2 @@ +typeof(numbers) # => Array(Int32) +numbers # => [2, 3, 4, 5, 6, 7] diff --git a/crystal/other.md b/crystal/other.md index 5087e2ad1..8d0d4a784 100644 --- a/crystal/other.md +++ b/crystal/other.md @@ -284,3 +284,8 @@ require "some_name" # Find it somewhere (standard library, src directory ![](examples/case_when_on_type.cr) +## Int64 Zero +{id: int64-zero} + +![](examples/int64_zero.cr) + diff --git a/crystal/range.md b/crystal/range.md index ed2d78660..4e926b2ae 100644 --- a/crystal/range.md +++ b/crystal/range.md @@ -47,3 +47,10 @@ ![](examples/range/step.cr) ![](examples/range/step.out) +## Range to Array +{id: range-to-array} +{i: to_a} + +![](examples/range/to_a.cr) +![](examples/range/to_a.out) +