Pattern Matching - Streams

#Stream<[
  enum: #Function<59.58486609/2 in Stream.transform/3>,
  funs: [#Function<47.58486609/1 in Stream.map/2>,
   #Function<47.58486609/1 in Stream.map/2>]
]>

How does on pattern match against this stream in a guard clause?

Since the steam type is private, you should match only on the fact that its a %Stream{} struct.

1 Like

If you want to make sure that the input to your function is a stream, you could do the following:

def my_function(stream) when is_struct(stream, Stream), do: # something

Alternatively, you could define your own guard:

defguard is_stream(stream) when is_struct(stream, Stream)
3 Likes