Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a small guide for Collections #364

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,6 @@
* [Guides](guides/README.md)
* [Performance](guides/performance.md)
* [Concurrency](guides/concurrency.md)
* [Collections] (guides/collections.md)
* [Testing](guides/testing.md)
* [Writing Shards](guides/writing_shards.md)
27 changes: 27 additions & 0 deletions guides/collections.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Collections

Collections of objects, such as [Array](https://crystal-lang.org/api/Array.html), [Hash](https://crystal-lang.org/api/Hash.html), and [Set](https://crystal-lang.org/api/Set.html) are powerful data structures for storing groups of data. Crystal offers a number of Modules to assist developers working with collections of objects in the Standard Library.


```
arr = Array(String).new
arr << "Foo"
arr << "Bar"
arr << "Baz"
arr << "Foo"

arr.size # returns 4
arr.empty? # returns false

arr.count "Foo" # returns 2
arr.count "Nope" # returns 0

arr.index { |i| i == "Baz" } # returns 1
arr.index { |i| i == "Nope" } # returns

arr.find { |i| i == "Foo" } # return "Foo"
arr.find { |i| i == "Nope" } # return nil

```

For full details, see the [Indexable](https://crystal-lang.org/api/Indexable.html), [Enumerable]((https://crystal-lang.org/api/Enumerable.html), [Iterable](https://crystal-lang.org/api/Iterable.html) Modules.