Skip to content

Commit

Permalink
refactor: move itertools
Browse files Browse the repository at this point in the history
  • Loading branch information
ayn2op committed Aug 30, 2024
1 parent 22cfa9b commit 942f9cc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/guilds_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sort"
"strings"

"github.com/ayn2op/go-itertools"
"github.com/ayn2op/discordo/pkg/itertools"
"github.com/diamondburned/arikawa/v3/discord"
"github.com/diamondburned/arikawa/v3/gateway"
"github.com/gdamore/tcell/v2"
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.23.0
require (
github.com/BurntSushi/toml v1.4.0
github.com/atotto/clipboard v0.1.4
github.com/ayn2op/go-itertools v0.0.0-20240820180307-e12e136d577b
github.com/diamondburned/arikawa/v3 v3.4.0
github.com/gdamore/tcell/v2 v2.7.4
github.com/rivo/tview v0.0.0-20240818110301-fd649dbf1223
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4u
github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/ayn2op/go-itertools v0.0.0-20240820180307-e12e136d577b h1:TPJYmEtguvPOZLqxxV2c4gm9yyDfjS2mPxFW1YeXNFE=
github.com/ayn2op/go-itertools v0.0.0-20240820180307-e12e136d577b/go.mod h1:uYHKkErkb+ZyQKE4OjqqVpx9/MskFvTem7JhJk/86To=
github.com/danieljoos/wincred v1.2.2 h1:774zMFJrqaeYCK2W57BgAem/MLi6mtSE47MB6BOJ0i0=
github.com/danieljoos/wincred v1.2.2/go.mod h1:w7w4Utbrz8lqeMbDAK0lkNJUv5sAOkFi7nd/ogr0Uh8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand All @@ -30,8 +28,6 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/tview v0.0.0-20240807205129-e4c497cc59ed h1:bd91xrd1ECzkEJ4XttUJEiyyGBHQdaOmXVEffJbAm6M=
github.com/rivo/tview v0.0.0-20240807205129-e4c497cc59ed/go.mod h1:02iFIz7K/A9jGCvrizLPvoqr4cEIx7q54RH5Qudkrss=
github.com/rivo/tview v0.0.0-20240818110301-fd649dbf1223 h1:N+DggyldbUDqFlk0b8JeRjB9zGpmQ8wiKpq+VBbzRso=
github.com/rivo/tview v0.0.0-20240818110301-fd649dbf1223/go.mod h1:02iFIz7K/A9jGCvrizLPvoqr4cEIx7q54RH5Qudkrss=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand Down
15 changes: 15 additions & 0 deletions pkg/itertools/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package itertools

import "iter"

func Filter[I any](in iter.Seq[I], predicate func(I) bool) iter.Seq[I] {
return func(yield func(I) bool) {
for i := range in {
if predicate(i) {
if !yield(i) {
return
}
}
}
}
}
13 changes: 13 additions & 0 deletions pkg/itertools/map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package itertools

import "iter"

func Map[I, O any](in iter.Seq[I], f func(I) O) iter.Seq[O] {
return func(yield func(O) bool) {
for i := range in {
if !yield(f(i)) {
return
}
}
}
}

0 comments on commit 942f9cc

Please sign in to comment.