Skip to content

Commit 340e63b

Browse files
Add doctests to kernel guards (#14544)
1 parent c39286e commit 340e63b

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,17 @@ defmodule Kernel do
735735
Returns `true` if `term` is a floating-point number, otherwise returns `false`.
736736
737737
Allowed in guard tests. Inlined by the compiler.
738+
739+
## Examples
740+
741+
iex> is_float(2.15)
742+
true
743+
744+
iex> is_float(3.45e5)
745+
true
746+
747+
iex> is_float(5)
748+
false
738749
"""
739750
@doc guard: true
740751
@spec is_float(term) :: boolean
@@ -786,6 +797,14 @@ defmodule Kernel do
786797
Returns `true` if `term` is an integer, otherwise returns `false`.
787798
788799
Allowed in guard tests. Inlined by the compiler.
800+
801+
## Examples
802+
803+
iex> is_integer(5)
804+
true
805+
806+
iex> is_integer(5.0)
807+
false
789808
"""
790809
@doc guard: true
791810
@spec is_integer(term) :: boolean
@@ -797,6 +816,17 @@ defmodule Kernel do
797816
Returns `true` if `term` is a list with zero or more elements, otherwise returns `false`.
798817
799818
Allowed in guard tests. Inlined by the compiler.
819+
820+
## Examples
821+
822+
iex> is_list([1, 2, 3])
823+
true
824+
825+
iex> is_list(key: :sum, value: 3)
826+
true
827+
828+
iex> is_list({1, 2, 3})
829+
false
800830
"""
801831
@doc guard: true
802832
@spec is_list(term) :: boolean
@@ -809,6 +839,17 @@ defmodule Kernel do
809839
otherwise returns `false`.
810840
811841
Allowed in guard tests. Inlined by the compiler.
842+
843+
## Examples
844+
845+
iex> is_number(2.15)
846+
true
847+
848+
iex> is_number(5)
849+
true
850+
851+
iex> is_number(:one)
852+
false
812853
"""
813854
@doc guard: true
814855
@spec is_number(term) :: boolean
@@ -820,6 +861,18 @@ defmodule Kernel do
820861
Returns `true` if `term` is a PID (process identifier), otherwise returns `false`.
821862
822863
Allowed in guard tests. Inlined by the compiler.
864+
865+
## Examples
866+
867+
iex> {:ok, agent_pid} = Agent.start_link(fn -> 0 end)
868+
iex> is_pid(agent_pid)
869+
true
870+
871+
iex> is_pid(self())
872+
true
873+
874+
iex> is_pid(:pid)
875+
false
823876
"""
824877
@doc guard: true
825878
@spec is_pid(term) :: boolean
@@ -831,6 +884,15 @@ defmodule Kernel do
831884
Returns `true` if `term` is a port identifier, otherwise returns `false`.
832885
833886
Allowed in guard tests. Inlined by the compiler.
887+
888+
## Examples
889+
890+
iex> [port | _] = Port.list()
891+
iex> is_port(port)
892+
true
893+
894+
iex> is_port(:port)
895+
false
834896
"""
835897
@doc guard: true
836898
@spec is_port(term) :: boolean
@@ -842,6 +904,15 @@ defmodule Kernel do
842904
Returns `true` if `term` is a reference, otherwise returns `false`.
843905
844906
Allowed in guard tests. Inlined by the compiler.
907+
908+
## Examples
909+
910+
iex> ref = make_ref()
911+
iex> is_reference(ref)
912+
true
913+
914+
iex> is_reference(:ref)
915+
false
845916
"""
846917
@doc guard: true
847918
@spec is_reference(term) :: boolean
@@ -853,6 +924,17 @@ defmodule Kernel do
853924
Returns `true` if `term` is a tuple, otherwise returns `false`.
854925
855926
Allowed in guard tests. Inlined by the compiler.
927+
928+
## Examples
929+
930+
iex> is_tuple({1, 2, 3})
931+
true
932+
933+
iex> is_tuple({})
934+
true
935+
936+
iex> is_tuple(true)
937+
false
856938
"""
857939
@doc guard: true
858940
@spec is_tuple(term) :: boolean

0 commit comments

Comments
 (0)