Skip to content

Commit

Permalink
refactored list_buckets for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
lsxliron authored and mmmries committed Apr 17, 2024
1 parent c8df3fe commit bb4c5f0
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/gnat/jetstream/api/kv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -281,17 +281,18 @@ defmodule Gnat.Jetstream.API.KV do
"""
@spec list_buckets(conn :: Gnat.t()) :: {:error, term()} | {:ok, list(String.t())}
def list_buckets(conn) do
case Stream.list(conn) do
{:ok, %{streams: streams}} ->
{:ok,
streams
|> Enum.flat_map(fn bucket ->
case is_kv_bucket_stream?(bucket) do
true -> [bucket |> String.trim_leading(@stream_prefix)]
_ -> []
end
end)}

with {:ok, %{streams: streams}} <- Stream.list(conn) do
stream_names =
streams
|> Enum.flat_map(fn bucket ->
if is_kv_bucket_stream?(bucket) do
[bucket |> String.trim_leading(@stream_prefix)]
else
[]
end
end)
{:ok, stream_names}
else
{:error, reason} ->
{:error, reason}
end
Expand Down

0 comments on commit bb4c5f0

Please sign in to comment.