Skip to content

Commit

Permalink
update to latest version of gleam
Browse files Browse the repository at this point in the history
  • Loading branch information
schurhammer committed Feb 15, 2024
1 parent 43ef734 commit b938f43
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: erlef/[email protected]
with:
otp-version: "25.2"
gleam-version: "0.29.0"
gleam-version: "0.34.1"
rebar3-version: "3"
# elixir-version: "1.14.2"
- run: gleam format --check src test
Expand Down
4 changes: 2 additions & 2 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repository = { type = "github", user = "schurhammer", repo = "gleamy_structures"
links = [{ title = "Website", href = "https://github.com/schurhammer/gleamy_structures" }]

[dependencies]
gleam_stdlib = "~> 0.29"
gleam_stdlib = "~> 0.34"

[dev-dependencies]
gleeunit = "~> 0.10"
gleeunit = "~> 1.0"
8 changes: 4 additions & 4 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# You typically do not need to edit this file

packages = [
{ name = "gleam_stdlib", version = "0.29.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "DB981FB670AAC6392C0694AF639C49ADF1C2E42664D5F90BBF573102667B8E53" },
{ name = "gleeunit", version = "0.10.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "ECEA2DE4BE6528D36AFE74F42A21CDF99966EC36D7F25DEB34D47DD0F7977BAF" },
{ name = "gleam_stdlib", version = "0.35.1", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5443EEB74708454B65650FEBBB1EF5175057D1DEC62AEA9D7C6D96F41DA79152" },
{ name = "gleeunit", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "D364C87AFEB26BDB4FB8A5ABDE67D635DC9FA52D6AB68416044C35B096C6882D" },
]

[requirements]
gleam_stdlib = "~> 0.29.0"
gleeunit = "~> 0.10.1"
gleam_stdlib = { version = "~> 0.34" }
gleeunit = { version = "~> 1.0" }
2 changes: 1 addition & 1 deletion src/gleamy_structures/heap/leftist_heap.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Based on "Purely Functional Data Structures" by Okasaki (1998)

import gleam/order.{Gt, Order}
import gleam/order.{type Order, Gt}

type T(a) {
E
Expand Down
2 changes: 1 addition & 1 deletion src/gleamy_structures/heap/pairing_heap.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Based on "Purely Functional Data Structures" by Okasaki (1998)

import gleam/order.{Gt, Order}
import gleam/order.{type Order, Gt}

type T(a) {
E
Expand Down
26 changes: 10 additions & 16 deletions src/gleamy_structures/map.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gleam/order.{Order}
import gleam/order.{type Order}
import gleam/list
import gleamy_structures/tree/red_black_tree_kv as tree

Expand Down Expand Up @@ -41,16 +41,12 @@ pub fn fold(
}

pub fn filter(in map: Map(k, v), for property: fn(k, v) -> Bool) -> Map(k, v) {
tree.fold(
map,
map,
fn(map, k, v) {
case property(k, v) {
True -> map
False -> tree.delete(map, k)
}
},
)
tree.fold(map, map, fn(map, k, v) {
case property(k, v) {
True -> map
False -> tree.delete(map, k)
}
})
}

pub fn merge(this first: Map(k, v), and second: Map(k, v)) -> Map(k, v) {
Expand All @@ -73,11 +69,9 @@ pub fn from_list(
members: List(#(k, v)),
compare: fn(k, k) -> Order,
) -> Map(k, v) {
list.fold(
members,
tree.new(compare),
fn(tree, i) { tree.insert(tree, i.0, i.1) },
)
list.fold(members, tree.new(compare), fn(tree, i) {
tree.insert(tree, i.0, i.1)
})
}

pub fn to_list(map: Map(k, v)) -> List(#(k, v)) {
Expand Down
16 changes: 6 additions & 10 deletions src/gleamy_structures/non_empty_list.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ pub fn map(list: NonEmptyList(a), transform: fn(a) -> b) -> NonEmptyList(b) {
}

pub fn filter(list: NonEmptyList(a), predicate: fn(a) -> Bool) -> List(a) {
fold(
list,
[],
fn(acc, item) {
case predicate(item) {
True -> [item, ..acc]
False -> acc
}
},
)
fold(list, [], fn(acc, item) {
case predicate(item) {
True -> [item, ..acc]
False -> acc
}
})
|> list.reverse()
}

Expand Down
2 changes: 1 addition & 1 deletion src/gleamy_structures/priority_queue.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gleam/order.{Order}
import gleam/order.{type Order}
import gleam/list
import gleamy_structures/heap/pairing_heap as heap

Expand Down
34 changes: 13 additions & 21 deletions src/gleamy_structures/set.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gleam/order.{Order}
import gleam/order.{type Order}
import gleam/list
import gleamy_structures/tree/red_black_tree as tree

Expand All @@ -17,16 +17,12 @@ pub fn delete(from set: Set(a), this member: a) -> Set(a) {
}

pub fn filter(in set: Set(a), for property: fn(a) -> Bool) -> Set(a) {
tree.fold(
set,
set,
fn(set, i) {
case property(i) {
True -> set
False -> tree.delete(set, i)
}
},
)
tree.fold(set, set, fn(set, i) {
case property(i) {
True -> set
False -> tree.delete(set, i)
}
})
}

pub fn fold(over set: Set(a), from initial: b, with reducer: fn(b, a) -> b) -> b {
Expand All @@ -42,16 +38,12 @@ pub fn insert(into set: Set(a), this member: a) -> Set(a) {
}

pub fn intersection(of first: Set(a), and second: Set(a)) -> Set(a) {
tree.fold(
second,
tree.clear(first),
fn(a, i) {
case tree.find(first, i) {
Ok(_) -> tree.insert(a, i)
Error(_) -> a
}
},
)
tree.fold(second, tree.clear(first), fn(a, i) {
case tree.find(first, i) {
Ok(_) -> tree.insert(a, i)
Error(_) -> a
}
})
}

pub fn new(compare: fn(a, a) -> Order) -> Set(a) {
Expand Down
2 changes: 1 addition & 1 deletion src/gleamy_structures/tree/binary_search_tree.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import gleam/order.{Eq, Gt, Lt, Order}
import gleam/order.{type Order, Eq, Gt, Lt}

type Node(a) {
Empty
Expand Down
2 changes: 1 addition & 1 deletion src/gleamy_structures/tree/red_black_tree.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Based on "Deletion: The curse of the red-black tree" by Germane (2014)

import gleam/order.{Eq, Gt, Lt, Order}
import gleam/order.{type Order, Eq, Gt, Lt}

type Color {
R
Expand Down
2 changes: 1 addition & 1 deletion src/gleamy_structures/tree/red_black_tree_kv.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Based on "Deletion: The curse of the red-black tree" by Germane (2014)

import gleam/order.{Eq, Gt, Lt, Order}
import gleam/order.{type Order, Eq, Gt, Lt}

type Color {
R
Expand Down
2 changes: 1 addition & 1 deletion test/priority_queue_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn reorder_test() {
|> should.equal([1, 1, 3, 4, 5])

let reverse_queue =
queue.reorder(queue, fn(a, b) { order.reverse(int.compare(a, b)) })
queue.reorder(queue, fn(a, b) { order.reverse(int.compare)(a, b) })

queue.to_list(reverse_queue)
|> should.equal([5, 4, 3, 1, 1])
Expand Down

0 comments on commit b938f43

Please sign in to comment.