Skip to content

Commit

Permalink
no more function.compose
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed May 26, 2024
1 parent 67bdcd7 commit fc88f01
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/aoc_2020/day_4.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gleam/function
import gleam/int
import gleam/list
import gleam/result
Expand Down Expand Up @@ -36,7 +35,10 @@ fn process_passport(passport: String) -> List(#(String, String)) {
}

fn has_keys(passport: List(#(String, String)), keys: List(String)) -> Bool {
list.all(keys, function.compose(list.key_find(passport, _), result.is_ok))
list.all(keys, fn(x) {
list.key_find(passport, x)
|> result.is_ok
})
}

fn validate_as_int(s: String, min: Int, max: Int) -> Bool {
Expand Down
7 changes: 5 additions & 2 deletions src/aoc_2022/day_3.gleam
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gleam/function.{compose as c}
import gleam/list
import gleam/set
import gleam/string
Expand Down Expand Up @@ -38,7 +37,11 @@ pub fn pt_2(input: String) {
input
|> string.split("\n")
// get character set for each line
|> list.map(c(string.to_graphemes, set.from_list))
|> list.map(fn(s) {
s
|> string.to_graphemes
|> set.from_list
})
// split into chunks of 3
|> list.sized_chunk(3)
// set intersection of each group
Expand Down
4 changes: 1 addition & 3 deletions src/aoc_2022/day_5.gleam
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import gleam/dict.{type Dict as Map} as map
import gleam/function.{compose as c}
import gleam/int
import gleam/iterator.{type Iterator}
import gleam/list
import gleam/option.{Some}
import gleam/pair
import gleam/result
import gleam/string

Expand Down Expand Up @@ -59,7 +57,7 @@ fn solve(input, f) {
iterator.fold(moves, stacks, f)
|> map.to_list()
|> list.sort(fn(p1, p2) { int.compare(p1.0, p2.0) })
|> list.try_map(c(pair.second, list.first))
|> list.try_map(fn(p) { list.first(p.1) })

string.concat(firsts)
}
Expand Down

0 comments on commit fc88f01

Please sign in to comment.