Skip to content

Commit 849011a

Browse files
committed
Version 1.0.0
1 parent 4beebf6 commit 849011a

File tree

6 files changed

+117
-139
lines changed

6 files changed

+117
-139
lines changed

.github/workflows/test.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: test
32

43
on:
@@ -12,11 +11,12 @@ jobs:
1211
test:
1312
runs-on: ubuntu-latest
1413
steps:
15-
- uses: actions/checkout@v2.0.0
16-
- uses: erlef/setup-beam@v1.9.0
14+
- uses: actions/checkout@v4
15+
- uses: erlef/setup-beam@v1
1716
with:
18-
otp-version: "23.2"
19-
gleam-version: "0.21.0"
20-
- run: gleam format --check src test
17+
otp-version: "26.0.2"
18+
gleam-version: "1.5.1"
19+
rebar3-version: "3"
2120
- run: gleam deps download
22-
- run: gleam test
21+
- run: gleam test
22+
- run: gleam format --check src test

gleam.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "gleam_zlists"
2-
version = "0.0.4"
2+
version = "1.0.0"
33
licences = ["Apache-2.0"]
44
description = "A library for working with lazy lists in Gleam"
55

@@ -14,8 +14,8 @@ user = "mrdimosthenis"
1414
repo = "gleam_zlists"
1515

1616
[dependencies]
17-
gleam_stdlib = "~> 0.21"
18-
zlists = "~> 0.0"
17+
gleam_stdlib = "~> 0.40.0"
18+
zlists = "~> 0.0.4"
1919

2020
[dev-dependencies]
21-
gleeunit = "~> 0.6"
21+
gleeunit = "~> 1.2.0"

manifest.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# You typically do not need to edit this file
33

44
packages = [
5-
{ name = "gleam_stdlib", version = "0.21.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "FB03CD50B477867DA65B1318252ABA02F76175754762D15BF6C792CF5B85BCC4" },
6-
{ name = "gleeunit", version = "0.6.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "5BF486C3E135B7F5ED8C054925FC48E5B2C79016A39F416FD8CF2E860520EE55" },
5+
{ name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" },
6+
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
77
{ name = "zlists", version = "0.0.4", build_tools = ["mix", "rebar3"], requirements = [], otp_app = "zlists", source = "hex", outer_checksum = "BABC8B78984E4988DAFEB9E07A77F04D3F8EA208D49E60B6669DA43B0D2C2C4B" },
88
]
99

1010
[requirements]
11-
gleam_stdlib = "~> 0.21"
12-
gleeunit = "~> 0.6"
13-
zlists = "~> 0.0"
11+
gleam_stdlib = { version = "~> 0.40.0" }
12+
gleeunit = { version = "~> 1.2.0" }
13+
zlists = { version = "~> 0.0.4" }

src/gleam_zlists.gleam

+34-50
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//// For more information see [this website](https://github.com/mrdimosthenis/gleam_zlists).
44

55
import gleam/bool
6+
import gleam/iterator.{type Iterator, Done, Next}
67
import gleam/result
7-
import gleam/iterator.{Done, Iterator, Next}
88
import gleam_zlists/interface as api
99

1010
/// A type for representing lazy lists.
@@ -420,6 +420,7 @@ pub fn head(zlist: ZList(t)) -> Result(t, Nil) {
420420
case ls {
421421
[] -> Error(Nil)
422422
[v] -> Ok(v)
423+
[v, _, ..] -> Ok(v)
423424
}
424425
}
425426

@@ -447,7 +448,7 @@ pub fn tail(zlist: ZList(t)) -> Result(ZList(t), Nil) {
447448
|> to_list
448449
case ls {
449450
[] -> Error(Nil)
450-
[_] ->
451+
[_] | [_, _, ..] ->
451452
zlist
452453
|> drop(1)
453454
|> Ok
@@ -469,11 +470,11 @@ pub fn tail(zlist: ZList(t)) -> Result(ZList(t), Nil) {
469470
/// ```
470471
///
471472
pub fn uncons(zlist: ZList(t)) -> Result(#(t, ZList(t)), Nil) {
472-
case #(head(zlist), tail(zlist)) {
473-
#(Ok(hd), Ok(tl)) ->
473+
case head(zlist), tail(zlist) {
474+
Ok(hd), Ok(tl) ->
474475
#(hd, tl)
475476
|> Ok
476-
_ -> Error(Nil)
477+
_, _ -> Error(Nil)
477478
}
478479
}
479480

@@ -547,14 +548,11 @@ pub fn all(zlist: ZList(t), fun: fn(t) -> Bool) -> Bool {
547548
///
548549
pub fn any(zlist: ZList(t), fun: fn(t) -> Bool) -> Bool {
549550
let #(_, zls_b) =
550-
split_while(
551-
zlist,
552-
fn(x) {
553-
x
554-
|> fun
555-
|> bool.negate
556-
},
557-
)
551+
split_while(zlist, fn(x) {
552+
x
553+
|> fun
554+
|> bool.negate
555+
})
558556
zls_b
559557
|> is_empty
560558
|> bool.negate
@@ -728,14 +726,11 @@ pub fn with_index(zlist: ZList(t)) -> ZList(#(t, Int)) {
728726
pub fn unzip(zlist: ZList(#(a, b))) -> #(ZList(a), ZList(b)) {
729727
zlist
730728
|> reverse
731-
|> reduce(
732-
#(new(), new()),
733-
fn(it, acc) {
734-
let #(x, y) = it
735-
let #(acc_xs, acc_ys) = acc
736-
#(cons(acc_xs, x), cons(acc_ys, y))
737-
},
738-
)
729+
|> reduce(#(new(), new()), fn(it, acc) {
730+
let #(x, y) = it
731+
let #(acc_xs, acc_ys) = acc
732+
#(cons(acc_xs, x), cons(acc_ys, y))
733+
})
739734
}
740735

741736
/// Returns the sum of all elements. The elements should be `Float` numbers.
@@ -771,16 +766,12 @@ pub fn max(zlist: ZList(Float)) -> Result(Float, Nil) {
771766
|> uncons
772767
|> result.map(fn(x) {
773768
let #(hd, tl) = x
774-
reduce(
775-
tl,
776-
hd,
777-
fn(x, acc) {
778-
case x >. acc {
779-
True -> x
780-
False -> acc
781-
}
782-
},
783-
)
769+
reduce(tl, hd, fn(x, acc) {
770+
case x >. acc {
771+
True -> x
772+
False -> acc
773+
}
774+
})
784775
})
785776
}
786777

@@ -802,16 +793,12 @@ pub fn min(zlist: ZList(Float)) -> Result(Float, Nil) {
802793
|> uncons
803794
|> result.map(fn(x) {
804795
let #(hd, tl) = x
805-
reduce(
806-
tl,
807-
hd,
808-
fn(x, acc) {
809-
case x <. acc {
810-
True -> x
811-
False -> acc
812-
}
813-
},
814-
)
796+
reduce(tl, hd, fn(x, acc) {
797+
case x <. acc {
798+
True -> x
799+
False -> acc
800+
}
801+
})
815802
})
816803
}
817804

@@ -841,15 +828,12 @@ fn recurrent(
841828
s0: t1,
842829
rec_fun: fn(t, t1) -> Result(#(t, t1), Nil),
843830
) -> ZList(t) {
844-
api.new_2(
845-
singleton(x0),
846-
fn() {
847-
case rec_fun(x0, s0) {
848-
Ok(#(x1, s1)) -> recurrent(x1, s1, rec_fun)
849-
Error(Nil) -> new()
850-
}
851-
},
852-
)
831+
api.new_2(singleton(x0), fn() {
832+
case rec_fun(x0, s0) {
833+
Ok(#(x1, s1)) -> recurrent(x1, s1, rec_fun)
834+
Error(Nil) -> new()
835+
}
836+
})
853837
}
854838

855839
/// Converts the `iter` into a `ZList`.

src/gleam_zlists/interop.gleam

+53-53
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,79 @@
1-
pub external type ZList(a)
1+
pub type ZList(a)
22

3-
pub external fn new_1(List(t), fn() -> List(t)) -> ZList(t) =
4-
"zlists" "new"
3+
@external(erlang, "zlists", "new")
4+
pub fn new_1(x: List(t), y: fn() -> List(t)) -> ZList(t)
55

6-
pub external fn new_2(ZList(t), fn() -> ZList(t)) -> ZList(t) =
7-
"zlists" "new"
6+
@external(erlang, "zlists", "new")
7+
pub fn new_2(x: ZList(t), y: fn() -> ZList(t)) -> ZList(t)
88

9-
pub external fn generate(ZList(t), fn(t) -> ZList(t1)) -> ZList(t1) =
10-
"zlists" "generate"
9+
@external(erlang, "zlists", "generate")
10+
pub fn generate(x: ZList(t), y: fn(t) -> ZList(t1)) -> ZList(t1)
1111

12-
pub external fn recurrent_2(t, fn(t) -> t) -> ZList(t) =
13-
"zlists" "recurrent"
12+
@external(erlang, "zlists", "recurrent")
13+
pub fn recurrent_2(x: t, y: fn(t) -> t) -> ZList(t)
1414

15-
pub external fn recurrent_3(t, t1, fn(t, t1) -> #(t, t1)) -> ZList(t) =
16-
"zlists" "recurrent"
15+
@external(erlang, "zlists", "recurrent")
16+
pub fn recurrent_3(x: t, y: t1, z: fn(t, t1) -> #(t, t1)) -> ZList(t)
1717

18-
pub external fn foreach(fn(t) -> any, ZList(t)) -> Nil =
19-
"zlists" "foreach"
18+
@external(erlang, "zlists", "foreach")
19+
pub fn foreach(x: fn(t) -> any, y: ZList(t)) -> Nil
2020

21-
pub external fn foldl(fn(t, acc) -> acc, acc, ZList(t)) -> acc =
22-
"zlists" "foldl"
21+
@external(erlang, "zlists", "foldl")
22+
pub fn foldl(x: fn(t, acc) -> acc, y: acc, z: ZList(t)) -> acc
2323

24-
pub external fn map(fn(a) -> b, ZList(a)) -> ZList(b) =
25-
"zlists" "map"
24+
@external(erlang, "zlists", "map")
25+
pub fn map(x: fn(a) -> b, y: ZList(a)) -> ZList(b)
2626

27-
pub external fn seq(Int, Int, Int) -> ZList(Int) =
28-
"zlists" "seq"
27+
@external(erlang, "zlists", "seq")
28+
pub fn seq(x: Int, y: Int, z: Int) -> ZList(Int)
2929

30-
pub external fn dropwhile(fn(t) -> Bool, ZList(t)) -> ZList(t) =
31-
"zlists" "dropwhile"
30+
@external(erlang, "zlists", "dropwhile")
31+
pub fn dropwhile(x: fn(t) -> Bool, y: ZList(t)) -> ZList(t)
3232

33-
pub external fn drop(Int, ZList(t)) -> ZList(t) =
34-
"zlists" "drop"
33+
@external(erlang, "zlists", "drop")
34+
pub fn drop(x: Int, y: ZList(t)) -> ZList(t)
3535

36-
pub external fn takewhile(fn(t) -> Bool, ZList(t)) -> ZList(t) =
37-
"zlists" "takewhile"
36+
@external(erlang, "zlists", "takewhile")
37+
pub fn takewhile(x: fn(t) -> Bool, y: ZList(t)) -> ZList(t)
3838

39-
pub external fn take(Int, ZList(t)) -> ZList(t) =
40-
"zlists" "take"
39+
@external(erlang, "zlists", "take")
40+
pub fn take(x: Int, y: ZList(t)) -> ZList(t)
4141

42-
pub external fn filter(fn(t) -> Bool, ZList(t)) -> ZList(t) =
43-
"zlists" "filter"
42+
@external(erlang, "zlists", "filter")
43+
pub fn filter(x: fn(t) -> Bool, y: ZList(t)) -> ZList(t)
4444

45-
pub external fn expand(ZList(t)) -> List(t) =
46-
"zlists" "expand"
45+
@external(erlang, "zlists", "expand")
46+
pub fn expand(x: ZList(t)) -> List(t)
4747

48-
pub external fn append(ZList(ZList(t))) -> ZList(t) =
49-
"zlists" "append"
48+
@external(erlang, "zlists", "append")
49+
pub fn append(x: ZList(ZList(t))) -> ZList(t)
5050

51-
pub external fn scroll(Int, ZList(t)) -> #(List(t), ZList(t)) =
52-
"zlists" "scroll"
51+
@external(erlang, "zlists", "scroll")
52+
pub fn scroll(x: Int, y: ZList(t)) -> #(List(t), ZList(t))
5353

54-
pub external fn merge(ZList(t), ZList(t)) -> ZList(t) =
55-
"zlists" "merge"
54+
@external(erlang, "zlists", "merge")
55+
pub fn merge(x: ZList(t), y: ZList(t)) -> ZList(t)
5656

57-
pub external fn splitwith(fn(t) -> Bool, ZList(t)) -> #(List(t), ZList(t)) =
58-
"zlists" "splitwith"
57+
@external(erlang, "zlists", "splitwith")
58+
pub fn splitwith(x: fn(t) -> Bool, y: ZList(t)) -> #(List(t), ZList(t))
5959

60-
pub external fn cartesian(ZList(t), ZList(t)) -> ZList(t) =
61-
"zlists" "cartesian"
60+
@external(erlang, "zlists", "cartesian")
61+
pub fn cartesian(x: ZList(t), y: ZList(t)) -> ZList(t)
6262

63-
pub external fn zip(ZList(a), ZList(b)) -> ZList(#(a, b)) =
64-
"zlists" "zip"
63+
@external(erlang, "zlists", "zip")
64+
pub fn zip(x: ZList(a), y: ZList(b)) -> ZList(#(a, b))
6565

66-
pub external fn ziph(ZList(a), ZList(b)) -> ZList(#(a, b)) =
67-
"zlists" "ziph"
66+
@external(erlang, "zlists", "ziph")
67+
pub fn ziph(x: ZList(a), y: ZList(b)) -> ZList(#(a, b))
6868

69-
pub external fn unique_1(ZList(t)) -> ZList(t) =
70-
"zlists" "unique"
69+
@external(erlang, "zlists", "unique")
70+
pub fn unique_1(x: ZList(t)) -> ZList(t)
7171

72-
pub external fn unique_2(fn(t, t) -> Bool, ZList(t)) -> ZList(t) =
73-
"zlists" "unique"
72+
@external(erlang, "zlists", "unique")
73+
pub fn unique_2(x: fn(t, t) -> Bool, y: ZList(t)) -> ZList(t)
7474

75-
pub external fn count(ZList(t)) -> Int =
76-
"zlists" "count"
75+
@external(erlang, "zlists", "count")
76+
pub fn count(x: ZList(t)) -> Int
7777

78-
pub external fn print(ZList(t)) -> Nil =
79-
"zlists" "print"
78+
@external(erlang, "zlists", "print")
79+
pub fn print(x: ZList(t)) -> Nil

test/gleam_zlists/gleam_zlists_test.gleam

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import gleeunit/should
21
import gleam/int
3-
import gleam/string
4-
import gleam/result
52
import gleam/iterator.{Done, Next}
3+
import gleam/result
4+
import gleam/string
65
import gleam_zlists as zlist
6+
import gleeunit/should
77

88
pub fn append_test() {
99
zlist.append(zlist.range(1, 3, 1), zlist.range(4, 6, 1))
@@ -69,14 +69,11 @@ pub fn reduce_test() {
6969

7070
[1, 2, 3]
7171
|> zlist.of_list
72-
|> zlist.reduce(
73-
"0",
74-
fn(x, acc) {
75-
x
76-
|> int.to_string
77-
|> string.append(acc)
78-
},
79-
)
72+
|> zlist.reduce("0", fn(x, acc) {
73+
x
74+
|> int.to_string
75+
|> string.append(acc)
76+
})
8077
|> should.equal("3210")
8178
}
8279

@@ -701,15 +698,12 @@ pub fn of_iterator_test() {
701698
|> zlist.to_list
702699
|> should.equal([1, 2, 3])
703700

704-
iterator.unfold(
705-
100,
706-
fn(n) {
707-
case n {
708-
0 -> Done
709-
n -> Next(element: n, accumulator: n - 1)
710-
}
711-
},
712-
)
701+
iterator.unfold(100, fn(n) {
702+
case n {
703+
0 -> Done
704+
n -> Next(element: n, accumulator: n - 1)
705+
}
706+
})
713707
|> zlist.of_iterator
714708
|> zlist.take(3)
715709
|> zlist.to_list

0 commit comments

Comments
 (0)