Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/groguelon/ex_array
A wrapper module for Erlang's array.
https://github.com/groguelon/ex_array
array elixir
Last synced: about 1 month ago
JSON representation
A wrapper module for Erlang's array.
- Host: GitHub
- URL: https://github.com/groguelon/ex_array
- Owner: GRoguelon
- License: mit
- Created: 2023-04-21T04:28:40.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-16T22:04:32.000Z (10 months ago)
- Last Synced: 2024-09-18T14:10:45.204Z (2 months ago)
- Topics: array, elixir
- Language: Elixir
- Homepage: https://hex.pm/packages/ex_array
- Size: 39.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ExArray
A wrapper module for Erlang's array.
## Installation
Requires Elixir v1.14+:
```elixir
def deps do
[
{:ex_array, "~> 0.1.3"}
]
end
```Documentation can be found at: .
## Usage
### Initialization
Without options, `ExArray` fallbacks on:
* `size`: 0
* `default`: `nil`
* `fixed`: `false````elixir
ExArray.new()
#=> #ExArray<[], fixed=false, default=nil>ExArray.new(5)
#=> #ExArray<[nil, nil, nil, nil, nil], fixed=true, default=nil>
```You can provide options to change defaults:
```elixir
ExArray.new(size: 5, default: 0, fixed: false)
#=> #ExArray<[0, 0, 0, 0, 0], fixed=false, default=0>
```*Note:* When you specify a `size`, the array is automatically `fixed`.
### Setter
```elixir
arr = ExArray.new(size: 5, default: 0, fixed: false)arr = ExArray.set(arr, 1, "Hello")
#=> #ExArray<[0, "Hello", 0, 0, 0], fixed=false, default=0>ExArray.reset(arr, 1)
#=> #ExArray<[0, 0, 0, 0, 0], fixed=false, default=0>
```### Getter
```elixir
arr = ExArray.new() |> ExArray.set(1, "Hello")ExArray.get(arr, 0)
#=> nilExArray.get(arr, 1)
#=> "Hello"ExArray.size(arr)
#=> 2
```### Convertions
```elixir
arr = ExArray.new(3) |> ExArray.set(1, "Hello")ExArray.to_list(arr)
#=> [nil, "5", nil]ExArray.sparse_to_list(arr)
#=> ["Hello"]ExArray.to_orddict(arr)
#=> [{0, nil}, {1, "Hello"}, {2, nil}]ExArray.sparse_to_orddict(arr)
#=> [{1, "Hello"}]
```## Acknowledgments
This package is a fork of [takscape/elixir-array](https://github.com/takscape/elixir-array). The latest commit was in 2014 and the compilation was broken with recent versions of Elixir.