https://github.com/acook/enumerous
Handy functionality for your Crystal Arrays and Enumerables!
https://github.com/acook/enumerous
Last synced: 8 months ago
JSON representation
Handy functionality for your Crystal Arrays and Enumerables!
- Host: GitHub
- URL: https://github.com/acook/enumerous
- Owner: acook
- License: other
- Created: 2021-02-14T09:20:04.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-17T03:26:34.000Z (over 5 years ago)
- Last Synced: 2025-07-05T00:11:35.899Z (12 months ago)
- Language: Crystal
- Size: 31.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Enumerous
Handy functionality for your Arrays and Enumerables!
[](https://github.com/acook/enumerous/releases)
[](https://app.circleci.com/pipelines/github/acook/enumerous)
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
enumerous:
github: acook/enumerous
```
2. Run `shards install`
## Usage
### Erray Custom Array Type
An Erray is a strict superset of the core Array functionality without modifying any builtin classes. It works great with normal Arrays!
```crystal
require "enumerous/erray"
```
```crystal
has_different_elements = Erray{1,2}.similar [2,3] #=> false
contains_same_elements = Erray{1,2}.similar [2,1] #=> true
extra, missing = Erray{1,2}.diff [2,3] #=> {[3],[1]}
index_of_first_difference = Erray{1,2}.diff_index [1,3] #=> 1
{1,2}.find_and_map {|element| element > 1 && element.to_s } #=> "2"
```
If you do not want Erray in the global namespace just pass `-Dno_erray_alias` to the compiler and you can still access it from `Enumerous::Erray`.
### Optional Core Extension
```crystal
require "enumerous/coreext"
```
```crystal
has_different_elements = [1,2].similar [2,3] #=> false
contains_same_elements = [1,2].similar [2,1] #=> true
extra, missing = [1,2].diff [2,3] #=> {[3],[1]}
index_of_first_difference = [1,2].diff_index [1,3] #=> 1
[1,2].find_and_map {|element| element > 1 && element.to_s } #=> "2"
{a: 1, b: 2}.find_and_map {|key, value| value > 1 && "#{key}:#{value}" } #=> "b:2"
```
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [Anthony Cook](https://github.com/acook) - creator and maintainer