Skip to content

Commit aa1b678

Browse files
author
José Valim
committed
Improve URI and Stream docs
1 parent e53f75f commit aa1b678

File tree

2 files changed

+29
-38
lines changed

2 files changed

+29
-38
lines changed

lib/elixir/lib/stream.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,14 @@ defmodule Stream do
309309
310310
## Examples
311311
312-
iex> stream = Stream.each([1, 2, 3], fn(x) -> IO.puts x end)
312+
iex> stream = Stream.each([1, 2, 3], fn(x) -> self <- x end)
313313
iex> Enum.to_list(stream)
314+
iex> receive do: (x when is_integer(x) -> x)
314315
1
316+
iex> receive do: (x when is_integer(x) -> x)
315317
2
318+
iex> receive do: (x when is_integer(x) -> x)
316319
3
317-
[1,2,3]
318320
319321
"""
320322
@spec each(Enumerable.t, (element -> term)) :: Enumerable.t

lib/elixir/lib/uri.ex

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defmodule URI do
3636
Any scheme may be registered via `default_port/2`.
3737
3838
## Examples
39-
39+
4040
iex> URI.default_port("ftp")
4141
21
4242
@@ -61,11 +61,11 @@ defmodule URI do
6161
Encodes an enumerable into a query string.
6262
6363
Takes an enumerable (containing a sequence of two-item tuples)
64-
and returns a string of the form "key1=value1&key2=value2..." where
65-
keys and values are URL encoded as per `encode/1`. Keys and values can
64+
and returns a string of the form "key1=value1&key2=value2..." where
65+
keys and values are URL encoded as per `encode/1`. Keys and values can
6666
be any term that implements the `String.Chars` protocol (i.e. can be converted
6767
to a binary).
68-
68+
6969
## Examples
7070
7171
iex> hd = HashDict.new([{"foo", 1}, {"bar", "2"}])
@@ -85,15 +85,14 @@ defmodule URI do
8585
Use `query_decoder/1` if you want to iterate over each value manually.
8686
8787
## Examples
88-
88+
8989
iex> URI.decode_query("foo=1&bar=2") |> Dict.to_list
9090
[{"bar", "2"}, {"foo", "1"}]
9191
92-
> hd = HashDict.new()
93-
#HashDict<[]>
94-
> URI.decode_query("foo=1&bar=2", hd) |> HashDict.keys
92+
iex> hd = HashDict.new()
93+
iex> URI.decode_query("foo=1&bar=2", hd) |> HashDict.keys
9594
["bar", "foo"]
96-
> URI.decode_query("foo=1&bar=2", hd) |> HashDict.values
95+
iex> URI.decode_query("foo=1&bar=2", hd) |> HashDict.values
9796
["2", "1"]
9897
9998
"""
@@ -104,12 +103,12 @@ defmodule URI do
104103
@doc """
105104
Returns an iterator function over the query string that decodes
106105
the query string in steps.
107-
106+
108107
## Examples
109-
108+
110109
iex> URI.query_decoder("foo=1&bar=2") |> Enum.map &(&1)
111110
[{"foo", "1"}, {"bar", "2"}]
112-
111+
113112
"""
114113
def query_decoder(q) when is_binary(q) do
115114
Stream.unfold(q, &do_decoder/1)
@@ -141,12 +140,12 @@ defmodule URI do
141140

142141
@doc """
143142
Percent-escape a URI.
144-
143+
145144
## Example
146-
145+
147146
iex> URI.encode("http://elixir-lang.com/getting_started/2.html")
148147
"http%3A%2F%2Felixir-lang.com%2Fgetting_started%2F2.html"
149-
148+
150149
"""
151150
def encode(s), do: bc(<<c>> inbits s, do: <<percent(c) :: binary>>)
152151

@@ -169,12 +168,12 @@ defmodule URI do
169168

170169
@doc """
171170
Percent-unescape a URI.
172-
171+
173172
## Examples
174-
173+
175174
iex> URI.decode("http%3A%2F%2Felixir-lang.com")
176175
"http://elixir-lang.com"
177-
176+
178177
"""
179178
def decode(<<?%, hex1, hex2, tail :: binary >>) do
180179
<< bsl(hex2dec(hex1), 4) + hex2dec(hex2) >> <> decode(tail)
@@ -196,26 +195,16 @@ defmodule URI do
196195
@doc """
197196
Parses a URI into components.
198197
199-
URIs have portions that are handled specially for the
200-
particular scheme of the URI. For example, http and https
201-
have different default ports. Sometimes the parsing
202-
of portions themselves are different. This parser
203-
is extensible via behavior modules. If you have a
204-
module named `URI.MYSCHEME` with a function called
205-
`parse` that takes a single argument, the generically
206-
parsed URI, that function will be called when this
207-
parse function is passed a URI of that scheme. This
208-
allows you to build on top of what the URI library
209-
currently offers. You also need to define `default_port`
210-
which takes no arguments and returns the default port
211-
for that particular scheme. Take a look at `URI.HTTPS` for an
212-
example of one of these extension modules.
213-
198+
URIs have portions that are handled specially for the particular
199+
scheme of the URI. For example, http and https have different
200+
default ports. Such values can be accessed and registered via
201+
`URI.default_port/1` and `URI.default_port/2`.
202+
214203
## Examples
215-
204+
216205
iex> URI.parse("http://elixir-lang.org/")
217-
URI.Info[scheme: "http", path: "/", query: nil, fragment: nil,
218-
authority: "elixir-lang.org", userinfo: nil,
206+
URI.Info[scheme: "http", path: "/", query: nil, fragment: nil,
207+
authority: "elixir-lang.org", userinfo: nil,
219208
host: "elixir-lang.org", port: 80]
220209
221210
"""

0 commit comments

Comments
 (0)