File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -796,6 +796,29 @@ defmodule IO do
796796 :erlang . iolist_size ( iodata )
797797 end
798798
799+ @ doc """
800+ Checks if an IO data (the length is zero).
801+
802+ For more information about IO data, see the ["IO data"](#module-io-data)
803+ section in the module documentation.
804+
805+ ## Examples
806+
807+ iex> IO.iodata_empty?([])
808+ true
809+ iex> IO.iodata_empty?([""])
810+ true
811+ iex> IO.iodata_empty?([1, 2 | <<3, 4>>])
812+ false
813+
814+ """
815+ @ doc since: "1.20.0"
816+ @ spec iodata_empty? ( iodata ) :: boolean
817+ def iodata_empty? ( "" ) , do: true
818+ def iodata_empty? ( [ ] ) , do: true
819+ def iodata_empty? ( [ head | tail ] ) , do: iodata_empty? ( head ) and iodata_empty? ( tail )
820+ def iodata_empty? ( _ ) , do: false
821+
799822 @ doc false
800823 def each_stream ( device , line_or_codepoints ) do
801824 case read ( device , line_or_codepoints ) do
Original file line number Diff line number Diff line change @@ -273,6 +273,16 @@ defmodule IOTest do
273273 assert IO . binstream ( ) == IO . binstream ( :stdio , :line )
274274 end
275275
276+ test "iodata_empty?" do
277+ assert IO . iodata_empty? ( [ ] )
278+ assert IO . iodata_empty? ( "" )
279+ assert IO . iodata_empty? ( [ [ "" , [ ] ] | "" ] )
280+
281+ refute IO . iodata_empty? ( [ 1 ] )
282+ refute IO . iodata_empty? ( "1" )
283+ refute IO . iodata_empty? ( [ [ "" , [ ] ] | "ok" ] )
284+ end
285+
276286 defp assert_emits ( output , messages ) do
277287 for m <- messages do
278288 assert output =~ m
You can’t perform that action at this time.
0 commit comments