-
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
Showing
6 changed files
with
60 additions
and
56 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
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
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
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,32 @@ | ||
import gleam/list as li | ||
import gleam/pair.{first as pf, second as ps} | ||
import gleam/result as res | ||
|
||
pub fn index(ls: List(a), item: a) -> Result(Int, Nil) { | ||
li.index_map(ls, fn(x, index) { #(index, x) }) | ||
|> li.find(fn(x) { ps(x) == item }) | ||
|> res.map(pf) | ||
} | ||
|
||
pub fn from_pair(p: #(a, a)) -> List(a) { | ||
[pf(p), ps(p)] | ||
} | ||
|
||
pub fn index_filter(ls: List(a), f: fn(Int, a) -> Bool) -> List(a) { | ||
li.index_map(ls, fn(item, index) { #(index, item) }) | ||
|> li.filter(fn(x) { f(pf(x), ps(x)) }) | ||
|> li.map(ps) | ||
} | ||
|
||
pub fn contains(ls: List(a), item: a) -> Bool { | ||
res.is_ok(li.find(ls, fn(x) { x == item })) | ||
} | ||
|
||
pub fn swap(ls: List(a), ea: a, eb: a) -> List(a) { | ||
use x <- li.map(ls) | ||
case x { | ||
val if val == ea -> eb | ||
val if val == eb -> ea | ||
val -> val | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import gleeunit | ||
import gleeunit/should | ||
|
||
pub fn main() { | ||
gleeunit.main() | ||
|
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import gleam/io | ||
import gleam/string | ||
import gleeunit/should | ||
import print_queue as day05 | ||
|