Skip to content

Add doctests to kernel guards #14544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions lib/elixir/lib/kernel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,17 @@ defmodule Kernel do
Returns `true` if `term` is a floating-point number, otherwise returns `false`.

Allowed in guard tests. Inlined by the compiler.

## Examples

iex> is_float(2.15)
true

iex> is_float(3.45e5)
true

iex> is_float(5)
false
"""
@doc guard: true
@spec is_float(term) :: boolean
Expand Down Expand Up @@ -786,6 +797,14 @@ defmodule Kernel do
Returns `true` if `term` is an integer, otherwise returns `false`.

Allowed in guard tests. Inlined by the compiler.

## Examples

iex> is_integer(5)
true

iex> is_integer(5.0)
false
"""
@doc guard: true
@spec is_integer(term) :: boolean
Expand All @@ -797,6 +816,17 @@ defmodule Kernel do
Returns `true` if `term` is a list with zero or more elements, otherwise returns `false`.

Allowed in guard tests. Inlined by the compiler.

## Examples

iex> is_list([1, 2, 3])
true

iex> is_list(key: :sum, value: 3)
true

iex> is_list({1, 2, 3})
false
"""
@doc guard: true
@spec is_list(term) :: boolean
Expand All @@ -809,6 +839,17 @@ defmodule Kernel do
otherwise returns `false`.

Allowed in guard tests. Inlined by the compiler.

## Examples

iex> is_number(2.15)
true

iex> is_number(5)
true

iex> is_number(:one)
false
"""
@doc guard: true
@spec is_number(term) :: boolean
Expand All @@ -820,6 +861,18 @@ defmodule Kernel do
Returns `true` if `term` is a PID (process identifier), otherwise returns `false`.

Allowed in guard tests. Inlined by the compiler.

## Examples

iex> {:ok, agent_pid} = Agent.start_link(fn -> 0 end)
iex> is_pid(agent_pid)
true

iex> is_pid(self())
true

iex> is_pid(:pid)
false
"""
@doc guard: true
@spec is_pid(term) :: boolean
Expand All @@ -831,6 +884,15 @@ defmodule Kernel do
Returns `true` if `term` is a port identifier, otherwise returns `false`.

Allowed in guard tests. Inlined by the compiler.

## Examples

iex> [port | _] = Port.list()
iex> is_port(port)
true

iex> is_port(:port)
false
"""
@doc guard: true
@spec is_port(term) :: boolean
Expand All @@ -842,6 +904,15 @@ defmodule Kernel do
Returns `true` if `term` is a reference, otherwise returns `false`.

Allowed in guard tests. Inlined by the compiler.

## Examples

iex> ref = make_ref()
iex> is_reference(ref)
true

iex> is_reference(:ref)
false
"""
@doc guard: true
@spec is_reference(term) :: boolean
Expand All @@ -853,6 +924,17 @@ defmodule Kernel do
Returns `true` if `term` is a tuple, otherwise returns `false`.

Allowed in guard tests. Inlined by the compiler.

## Examples

iex> is_tuple({1, 2, 3})
true

iex> is_tuple({})
true

iex> is_tuple(true)
false
"""
@doc guard: true
@spec is_tuple(term) :: boolean
Expand Down