Skip to content

Commit aba380e

Browse files
author
Adriano Santos
committed
chore: removes a not so necessary function
1 parent 87fc8e9 commit aba380e

File tree

3 files changed

+2
-61
lines changed

3 files changed

+2
-61
lines changed

examples/helloworld_streams/lib/helloworld_streams/server.ex

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ defmodule HelloworldStreams.Server do
2222

2323
@spec say_server_hello(HelloRequest.t(), GRPC.Server.Stream.t()) :: any()
2424
def say_server_hello(request, materializer) do
25-
GRPCStream.unary(request, propagate_context: true, materializer: materializer)
26-
# Create new output stream from the request and drop the input
27-
|> GRPCStream.via(fn _metadata, %HelloRequest{} = msg ->
28-
create_output_stream(msg)
29-
|> GRPCStream.from()
30-
end)
25+
create_output_stream(request)
26+
|> GRPCStream.from()
3127
|> GRPCStream.run_with(materializer)
3228
end
3329

lib/grpc/stream.ex

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -233,42 +233,6 @@ defmodule GRPC.Stream do
233233
@spec ask!(t(), pid | atom, non_neg_integer) :: t()
234234
defdelegate ask!(stream, target, timeout \\ 5000), to: Operators
235235

236-
@doc """
237-
Replaces the current stream with a new one generated by the given factory function.
238-
The factory function receives the metadata and the current item as arguments.
239-
The factory function returns a new `GRPC.Stream` struct.
240-
241-
## Behavior
242-
Materializes the left stream by passing the first element to the right stream. Useful when used with single/2 to dynamically create a new output stream.
243-
244-
## Caution
245-
246-
This function materializes the current stream and replaces it with a new one.
247-
This can lead to performance issues if used excessively. In fact, it is more commonly used
248-
in following the `single/2` function.
249-
250-
## Parameters
251-
252-
- `stream`: The current `GRPC.Stream`.
253-
- `factory`: A function that takes metadata and the current item, returning a new `GRPC.Stream`.
254-
255-
## Returns
256-
- A new `GRPC.Stream` struct with the replaced flow.
257-
258-
## Example
259-
260-
GRPC.Stream.single(request)
261-
# Create new output stream from the request and drop the input
262-
|> GRPC.Stream.via(fn _metadata, msg ->
263-
create_output_stream(msg) # returns some Enumerable
264-
|> GRPC.Stream.from()
265-
end)
266-
|> GRPC.Stream.run_with(materializer)
267-
268-
"""
269-
@spec via(t(), (map(), term -> term)) :: t()
270-
defdelegate via(stream, factory), to: Operators
271-
272236
@doc """
273237
Filters the stream using the given predicate function.
274238

lib/grpc/stream/operators.ex

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,6 @@ defmodule GRPC.Stream.Operators do
5151
end
5252
end
5353

54-
@spec via(GRPCStream.t(), (map(), term -> term)) :: GRPCStream.t()
55-
def via(%GRPCStream{flow: flow, metadata: metadata} = _stream, factory)
56-
when is_function(factory, 2) do
57-
new =
58-
Flow.map(flow, fn item ->
59-
case factory.(metadata, item) do
60-
%GRPCStream{} = stream ->
61-
%GRPCStream{stream | metadata: metadata}
62-
63-
_ ->
64-
raise ArgumentError, "Expected factory to return a GRPC.Stream"
65-
end
66-
end)
67-
|> Enum.to_list()
68-
|> Enum.at(0)
69-
70-
%GRPCStream{new | flow: new.flow, metadata: new.metadata, options: new.options}
71-
end
72-
7354
@spec filter(GRPCStream.t(), (term -> term)) :: GRPCStream.t()
7455
def filter(%GRPCStream{flow: flow} = stream, filter) do
7556
%GRPCStream{stream | flow: Flow.filter(flow, filter)}

0 commit comments

Comments
 (0)