-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5758739
Showing
9 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: "26.0.2" | ||
gleam-version: "1.1.0" | ||
rebar3-version: "3" | ||
# elixir-version: "1.15.4" | ||
- run: gleam deps download | ||
- run: gleam test | ||
- run: gleam format --check src test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.beam | ||
*.ez | ||
/build | ||
erl_crash.dump |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# gary | ||
|
||
[![Package Version](https://img.shields.io/hexpm/v/gary)](https://hex.pm/packages/gary) | ||
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gary/) | ||
|
||
```sh | ||
gleam add gary | ||
``` | ||
```gleam | ||
import gary | ||
pub fn main() { | ||
// TODO: An example of the project in use | ||
} | ||
``` | ||
|
||
Further documentation can be found at <https://hexdocs.pm/gary>. | ||
|
||
## Development | ||
|
||
```sh | ||
gleam run # Run the project | ||
gleam test # Run the tests | ||
gleam shell # Run an Erlang shell | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name = "gary" | ||
version = "1.0.0" | ||
|
||
# Fill out these fields if you intend to generate HTML documentation or publish | ||
# your project to the Hex package manager. | ||
# | ||
# description = "" | ||
# licences = ["Apache-2.0"] | ||
# repository = { type = "github", user = "username", repo = "project" } | ||
# links = [{ title = "Website", href = "https://gleam.run" }] | ||
# | ||
# For a full reference of all the available options, you can have a look at | ||
# https://gleam.run/writing-gleam/gleam-toml/. | ||
|
||
[dependencies] | ||
gleam_stdlib = ">= 0.34.0 and < 2.0.0" | ||
gleam_erlang = ">= 0.25.0 and < 1.0.0" | ||
|
||
[dev-dependencies] | ||
gleeunit = ">= 1.0.0 and < 2.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# This file was generated by Gleam | ||
# You typically do not need to edit this file | ||
|
||
packages = [ | ||
{ name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" }, | ||
{ name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" }, | ||
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" }, | ||
] | ||
|
||
[requirements] | ||
gleam_erlang = { version = ">= 0.25.0 and < 1.0.0"} | ||
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" } | ||
gleeunit = { version = ">= 1.0.0 and < 2.0.0" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import gleam/erlang/atom | ||
import gleam/io | ||
import internal/array_bindings | ||
|
||
pub fn main() { | ||
array_bindings.new([ | ||
#(array_bindings.Size, 100), | ||
#(array_bindings.Default, -99), | ||
]) | ||
|> array_bindings.set(55, 1, _) | ||
|> io.debug() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import gleam/dict.{type Dict} | ||
import gleam/option.{type Option, None, Some} | ||
import internal/array_bindings.{ | ||
type ArrayOption, type ErlangArray, Default, Fixed, Size, | ||
} | ||
|
||
pub opaque type Array(t) { | ||
Array(array: ErlangArray(t), size: Option(Int), default: t) | ||
} | ||
|
||
// create arrays | ||
pub fn create(default: t) -> Array(t) { | ||
array_bindings.new([#(Default, default)]) | ||
|> Array(size: None, default: default) | ||
} | ||
|
||
pub fn create_fixed_size(size: Int, default: t) -> Array(t) { | ||
array_bindings.new_with_size(size, [#(Default, default)]) | ||
|> Array(size: Some(size), default: default) | ||
} | ||
|
||
// create other types from arrays | ||
pub fn create_from_list(list: List(t), default: t) -> Array(t) { | ||
array_bindings.from_list(list, default) | ||
|> Array(size: None, default: default) | ||
} | ||
|
||
pub fn create_from_dict(dict: Dict(Int, t), default: t) -> Array(t) { | ||
dict | ||
|> dict.to_list | ||
|> array_bindings.from_orddict(default) | ||
|> Array(size: None, default: default) | ||
} | ||
// modify array content | ||
|
||
// higher-order array functions | ||
|
||
// get array info | ||
|
||
// change the array's properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import gleam/dynamic | ||
import gleam/erlang/atom | ||
|
||
pub type ErlangArray(t) | ||
|
||
pub type ArrayOption { | ||
Default | ||
Fixed | ||
Size | ||
} | ||
|
||
// create arrays | ||
@external(erlang, "array", "new") | ||
pub fn new(options: List(#(ArrayOption, t))) -> ErlangArray(t) | ||
|
||
@external(erlang, "array", "new") | ||
pub fn new_with_size( | ||
size: Int, | ||
options: List(#(ArrayOption, t)), | ||
) -> ErlangArray(t) | ||
|
||
@external(erlang, "array", "from_list") | ||
pub fn from_list(list: List(t), default: t) -> ErlangArray(t) | ||
|
||
@external(erlang, "array", "from_orddict") | ||
pub fn from_orddict(list: List(#(Int, t)), default: t) -> ErlangArray(t) | ||
|
||
// create other types from arrays | ||
@external(erlang, "array", "to_list") | ||
pub fn to_list(array: ErlangArray(t)) -> List(t) | ||
|
||
@external(erlang, "array", "to_orddict") | ||
pub fn to_orddict(array: ErlangArray(t)) -> List(#(Int, t)) | ||
|
||
// modify array content | ||
@external(erlang, "array", "get") | ||
pub fn get(index: Int, array: ErlangArray(t)) -> t | ||
|
||
@external(erlang, "array", "set") | ||
pub fn set(index: Int, value: t, array: ErlangArray(t)) -> ErlangArray(t) | ||
|
||
@external(erlang, "array", "reset") | ||
pub fn reset(index: Int, array: ErlangArray(t)) -> ErlangArray(t) | ||
|
||
// higher-order array functions | ||
@external(erlang, "array", "map") | ||
pub fn map(f: fn(Int, a) -> b, array: ErlangArray(a)) -> ErlangArray(b) | ||
|
||
@external(erlang, "array", "sparse_map") | ||
pub fn sparse_map(f: fn(Int, a) -> b, array: ErlangArray(a)) -> ErlangArray(b) | ||
|
||
@external(erlang, "array", "foldr") | ||
pub fn foldr(f: fn(Int, a, b) -> b, acc: b, array: ErlangArray(a)) -> b | ||
|
||
@external(erlang, "array", "sparse_foldr") | ||
pub fn sparse_foldr(f: fn(Int, a, b) -> b, acc: b, array: ErlangArray(a)) -> b | ||
|
||
@external(erlang, "array", "foldl") | ||
pub fn foldl(f: fn(Int, a, b) -> b, acc: b, array: ErlangArray(a)) -> b | ||
|
||
@external(erlang, "array", "sparse_foldl") | ||
pub fn sparse_foldl(f: fn(Int, a, b) -> b, acc: b, array: ErlangArray(a)) -> b | ||
|
||
// get array info | ||
@external(erlang, "array", "default") | ||
pub fn default(array: ErlangArray(t)) -> t | ||
|
||
@external(erlang, "array", "size") | ||
pub fn size(array: ErlangArray(t)) -> t | ||
|
||
@external(erlang, "array", "is_fix") | ||
pub fn is_fix(array: ErlangArray(t)) -> Bool | ||
|
||
// change the array's properties | ||
@external(erlang, "array", "fix") | ||
pub fn fix(array: ErlangArray(t)) -> ErlangArray(t) | ||
|
||
@external(erlang, "array", "relax") | ||
pub fn relax(array: ErlangArray(t)) -> ErlangArray(t) | ||
|
||
@external(erlang, "array", "resize") | ||
pub fn resize(size: Int, array: ErlangArray(t)) -> ErlangArray(t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import gleeunit | ||
import gleeunit/should | ||
|
||
pub fn main() { | ||
gleeunit.main() | ||
} | ||
|
||
// gleeunit test functions end in `_test` | ||
pub fn hello_world_test() { | ||
1 | ||
|> should.equal(1) | ||
} |