From 401bf07f5908137cde206f2f755af83c9a7ff71e Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 28 Apr 2015 14:37:33 +0200 Subject: stdlib: Document and add normal distributed random value function It is needed in various tests. It uses the Ziggurat algorithm, which is the fastest that I know. --- lib/stdlib/doc/src/Makefile | 1 + lib/stdlib/doc/src/rand.xml | 246 +++++++++++++++++++++++++++++++++++++++++ lib/stdlib/doc/src/random.xml | 3 + lib/stdlib/doc/src/ref_man.xml | 1 + lib/stdlib/doc/src/specs.xml | 1 + 5 files changed, 252 insertions(+) create mode 100644 lib/stdlib/doc/src/rand.xml (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/Makefile b/lib/stdlib/doc/src/Makefile index f5d8b2072a..031e60f64e 100644 --- a/lib/stdlib/doc/src/Makefile +++ b/lib/stdlib/doc/src/Makefile @@ -81,6 +81,7 @@ XML_REF3_FILES = \ proplists.xml \ qlc.xml \ queue.xml \ + rand.xml \ random.xml \ re.xml \ sets.xml \ diff --git a/lib/stdlib/doc/src/rand.xml b/lib/stdlib/doc/src/rand.xml new file mode 100644 index 0000000000..178afda5a0 --- /dev/null +++ b/lib/stdlib/doc/src/rand.xml @@ -0,0 +1,246 @@ + + + + +
+ + 2015 + Ericsson AB. All Rights Reserved. + + + The contents of this file are subject to the Erlang Public License, + Version 1.1, (the "License"); you may not use this file except in + compliance with the License. You should have received a copy of the + Erlang Public License along with this software. If not, it can be + retrieved online at http://www.erlang.org/. + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + the License for the specific language governing rights and limitations + under the License. + + + + rand + + + 1 + + + + A + rand.xml +
+ rand + Pseudo random number generation + +

Random number generator.

+ +

The module contains several different algorithms and can be + extended with more in the future. The current uniform + distribution algorithms uses the + + scrambled Xorshift algorithms by Sebastiano Vigna and the + normal distribution algorithm uses the + + Ziggurat Method by Marsaglia and Tsang. +

+ +

The implemented algorithms are:

+ + exsplus Xorshift116+, 58 bits precision and period of 2^116-1. + exs64 Xorshift64*, 64 bits precision and a period of 2^64-1. + exs1024 Xorshift1024*, 64 bits precision and a period of 2^1024-1. + + +

The current default algorithm is exsplus. The default + may change in future. If a specific algorithm is required make + sure to always use seed/1 + to initialize the state. +

+ +

Every time a random number is requested, a state is used to + calculate it and a new state produced. The state can either be + implicit or it can be an explicit argument and return value. +

+ +

The functions with implicit state use the process dictionary + variable rand_seed to remember the current state.

+ +

If a process calls uniform/0 or + uniform/1 without + setting a seed first, seed/1 + is called automatically with the default algorithm and creates a + non-constant seed.

+ +

The functions with explicit state never use the process + dictionary.

+ +

Examples:

+
+      %% Simple usage. Creates and seeds the default algorithm
+      %% with a non-constant seed if not already done.
+      R0 = rand:uniform(),
+      R1 = rand:uniform(),
+
+      %% Use a given algorithm.
+      _ = rand:seed(exs1024),
+      R2 = rand:uniform(),
+
+      %% Use a given algorithm with a constant seed.
+      _ = rand:seed(exs1024, {123, 123534, 345345}),
+      R3 = rand:uniform(),
+
+      %% Use the functional api with non-constant seed.
+      S0 = rand:seed_s(exsplus),
+      {R4, S1} = rand:uniform_s(S0),
+
+      %% Create a standard normal deviate.
+      {SND0, S2} = rand:normal_s(S1),
+    
+ +

This random number generator is not cryptographically + strong. If a strong cryptographic random number generator is + needed, use one of functions in the + crypto + module, for example crypto:rand_bytes/1.

+
+ + + + + + + +

Algorithm dependent state.

+
+ + + +

Algorithm dependent state which can be printed or saved to file.

+
+
+ + + + + Seed random number generator + + +

Seeds random number generation with the given algorithm and time dependent + data if AlgOrExpState is an algorithm.

+

Otherwise recreates the exported seed in the process + dictionary, and returns the state. + See also: export_seed/0.

+
+
+ + + Seed random number generator + +

Seeds random number generation with the given algorithm and time dependent + data if AlgOrExpState is an algorithm.

+

Otherwise recreates the exported seed and returns the state. + See also: export_seed/0.

+
+
+ + + Seed the random number generation + +

Seeds random number generation with the given algorithm and + integers in the process dictionary and returns + the state.

+
+
+ + + Seed the random number generation + +

Seeds random number generation with the given algorithm and + integers and returns the state.

+
+
+ + + + Export the random number generation state + +

Returns the random number state in an external format. + To be used with seed/1.

+
+
+ + + + Export the random number generation state + +

Returns the random number generator state in an external format. + To be used with seed/1.

+
+
+ + + + Return a random float + + +

Returns a random float uniformly distributed in the value + range 0.0 < X < 1.0 and + updates the state in the process dictionary.

+
+
+ + + Return a random float + +

Given a state, uniform_s/1 returns a random float + uniformly distributed in the value range 0.0 < + X < 1.0 and a new state.

+
+
+ + + + Return a random integer + + +

Given an integer N >= 1, + uniform/1 returns a random integer uniformly + distributed in the value range + 1 <= X <= N and + updates the state in the process dictionary.

+
+
+ + + Return a random integer + +

Given an integer N >= 1 and a state, + uniform_s/2 returns a random integer uniformly + distributed in the value range 1 <= X <= + N and a new state.

+
+
+ + + + Return a standard normal distributed random float + +

Returns a standard normal deviate float (that is, the mean + is 0 and the standard deviation is 1) and updates the state in + the process dictionary.

+
+
+ + + Return a standard normal distributed random float + +

Given a state, normal_s/1 returns a standard normal + deviate float (that is, the mean is 0 and the standard + deviation is 1) and a new state.

+
+
+ +
+
diff --git a/lib/stdlib/doc/src/random.xml b/lib/stdlib/doc/src/random.xml index 2cc621ffc3..e475cda23d 100644 --- a/lib/stdlib/doc/src/random.xml +++ b/lib/stdlib/doc/src/random.xml @@ -48,6 +48,9 @@

It should be noted that this random number generator is not cryptographically strong. If a strong cryptographic random number generator is needed for example crypto:rand_bytes/1 could be used instead.

+

The new and improved rand module should be used + instead of this module.

diff --git a/lib/stdlib/doc/src/ref_man.xml b/lib/stdlib/doc/src/ref_man.xml index ea4009dc3e..459fc8c8ed 100644 --- a/lib/stdlib/doc/src/ref_man.xml +++ b/lib/stdlib/doc/src/ref_man.xml @@ -78,6 +78,7 @@ + diff --git a/lib/stdlib/doc/src/specs.xml b/lib/stdlib/doc/src/specs.xml index fd77b52da6..f12e00b263 100644 --- a/lib/stdlib/doc/src/specs.xml +++ b/lib/stdlib/doc/src/specs.xml @@ -44,6 +44,7 @@ + -- cgit v1.2.3 From 9b2988b5409dbd629ce57bf89fa1c3bad69b2a42 Mon Sep 17 00:00:00 2001 From: Andras Horvath Date: Tue, 7 Apr 2015 13:23:10 +0100 Subject: Delete superfluous comma from `filtermap' example The code explaining the behaviour of `filtermap/2` had a syntax error and wouldn't compile --- lib/stdlib/doc/src/lists.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/lists.xml b/lib/stdlib/doc/src/lists.xml index ee3c51c62c..dcc08d008b 100644 --- a/lib/stdlib/doc/src/lists.xml +++ b/lib/stdlib/doc/src/lists.xml @@ -176,7 +176,7 @@ filtermap(Fun, List1) -> false -> Acc; true -> [Elem|Acc]; {true,Value} -> [Value|Acc] - end, + end end, [], List1).

Example:

-- 
cgit v1.2.3


From 5c192ac2faf510c24a4f9c9936dd580d5d304183 Mon Sep 17 00:00:00 2001
From: Bruce Yinhe 
Date: Fri, 20 Mar 2015 15:25:00 +0100
Subject: Fixed a typo in Maps doc

---
 lib/stdlib/doc/src/maps.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'lib/stdlib/doc/src')

diff --git a/lib/stdlib/doc/src/maps.xml b/lib/stdlib/doc/src/maps.xml
index 59c26d9896..e46068230a 100644
--- a/lib/stdlib/doc/src/maps.xml
+++ b/lib/stdlib/doc/src/maps.xml
@@ -339,7 +339,7 @@ false
 			
 			
 				

- Returns a complete list of values, in arbitrary order, contained in map M. + Returns a complete list of values, in arbitrary order, contained in map Map.

The call will fail with a {badmap,Map} exception if Map is not a map. -- cgit v1.2.3 From 6e24ffab6c682383a1c284fc066e59c680c4c62e Mon Sep 17 00:00:00 2001 From: Richard Carlsson Date: Mon, 20 Apr 2015 09:51:49 +0200 Subject: Add uptime() shell command --- lib/stdlib/doc/src/c.xml | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/c.xml b/lib/stdlib/doc/src/c.xml index b49fa6ad67..b43d4786ae 100644 --- a/lib/stdlib/doc/src/c.xml +++ b/lib/stdlib/doc/src/c.xml @@ -231,6 +231,14 @@ compile:file(File, Options ++ [report_errors, report_w in the network.

+ + + Print node uptime + +

Prints the node uptime (as given by + erlang:statistics(wall_clock)), in human-readable form.

+
+
xm(ModSpec) -> void() Cross reference check a module -- cgit v1.2.3 From e09dd66dc4d89c62ddfd8c19791f9678d5d787c6 Mon Sep 17 00:00:00 2001 From: Erlang/OTP Date: Tue, 12 May 2015 18:18:55 +0200 Subject: Prepare release --- lib/stdlib/doc/src/notes.xml | 218 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 218 insertions(+) (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/notes.xml b/lib/stdlib/doc/src/notes.xml index 301a5ee2e8..3914a9bc0e 100644 --- a/lib/stdlib/doc/src/notes.xml +++ b/lib/stdlib/doc/src/notes.xml @@ -30,6 +30,224 @@

This document describes the changes made to the STDLIB application.

+
STDLIB 2.5 + +
Fixed Bugs and Malfunctions + + +

+ Fix handling of single dot in filename:join/2

+

+ The reference manual says that filename:join(A,B) is + equivalent to filename:join([A,B]). In some rare cases + this turns out not to be true. For example:

+

+ filename:join("/a/.","b") -> "/a/./b" vs + filename:join(["/a/.","b"]) -> "/a/b".

+

+ This has been corrected. A single dot is now only kept if + it occurs at the very beginning or the very end of the + resulting path.

+

+ *** POTENTIAL INCOMPATIBILITY ***

+

+ Own Id: OTP-12158

+
+ +

+ The undocumented option generic_debug for + gen_server has been removed.

+

+ Own Id: OTP-12183

+
+ +

+ erl_lint:icrt_export/4 has been rewritten to make the + code really follow the scoping rules of Erlang, and not + just in most situations by accident.

+

+ Own Id: OTP-12186

+
+ +

+ Add 'trim_all' option to binary:split/3

+

+ This option can be set to remove _ALL_ empty parts of the + result of a call to binary:split/3.

+

+ Own Id: OTP-12301

+
+ +

Correct orddict(3) regarding evaluation order of + fold() and map().

+

+ Own Id: OTP-12651 Aux Id: seq12832

+
+ +

+ Correct maps module error exceptions

+

+ Bad input to maps module function will now yield the + following exceptions: {badmap,NotMap} + or, badarg

+

+ Own Id: OTP-12657

+
+ +

+ It is now possible to paste text in JCL mode (using + Ctrl-Y) that has been copied in the previous shell + session. Also a bug that caused the JCL mode to crash + when pasting text has been fixed.

+

+ Own Id: OTP-12673

+
+
+
+ + +
Improvements and New Features + + +

+ Allow maps for supervisor flags and child specs

+

+ Earlier, supervisor flags and child specs were given as + tuples. While this is kept for backwards compatibility, + it is now also allowed to give these parameters as maps, + see sup_flags + and child_spec.

+

+ Own Id: OTP-11043

+
+ +

+ A new system message, terminate, is added. This + can be sent with sys:terminate/2,3. If the + receiving process handles system messages properly it + will terminate shortly after receiving this message.

+

+ The new function proc_lib:stop/1,3 utilizes this + new system message and monitors the receiving process in + order to facilitate a synchronous stop mechanism for + 'special processes'.

+

+ proc_lib:stop/1,3 is used by the following + functions:

+

+ gen_server:stop/1,3 (new) + gen_fsm:stop/1,3 (new) + gen_event:stop/1,3 (modified to be + synchronous) wx_object:stop/1,3 + (new)

+

+ Own Id: OTP-11173 Aux Id: seq12353

+
+ +

+ Remove the pg module, which has been deprecated + through OTP-17, is now removed from the STDLIB + application. This module has been marked experimental for + more than 15 years, and has largely been superseded by + the pg2 module from the Kernel application.

+

+ Own Id: OTP-11907

+
+ +

+ New BIF: erlang:get_keys/0, lists all keys + associated with the process dictionary. Note: + erlang:get_keys/0 is auto-imported.

+

+ *** POTENTIAL INCOMPATIBILITY ***

+

+ Own Id: OTP-12151 Aux Id: seq12521

+
+ +

Add three new functions to io_lib-- + scan_format/2, unscan_format/1, and + build_text/1-- which expose the parsed form of the + format control sequences to make it possible to easily + modify or filter the input to io_lib:format/2. + This can e.g. be used in order to replace unbounded-size + control sequences like ~w or ~p with + corresponding depth-limited ~W and ~P + before doing the actual formatting.

+

+ Own Id: OTP-12167

+
+ +

Introduce the erl_anno module, an abstraction + of the second element of tokens and tuples in the + abstract format.

+

+ Own Id: OTP-12195

+
+ +

+ Support variables as Map keys in expressions and patterns

+

Erlang will accept any expression as keys in Map + expressions and it will accept literals or bound + variables as keys in Map patterns.

+

+ Own Id: OTP-12218

+
+ +

The last traces of Mnemosyne Rules have been removed. +

+

+ Own Id: OTP-12257

+
+ +

+ Properly support maps in match_specs

+

+ Own Id: OTP-12270

+
+ +

+ New function ets:take/2. Works the same as + ets:delete/2 but also returns the deleted + object(s).

+

+ Own Id: OTP-12309

+
+ +

string:tokens/2 is somewhat faster, especially + if the list of separators only contains one separator + character.

+

+ Own Id: OTP-12422 Aux Id: seq12774

+
+ +

+ Prevent zip:zip_open/[12] from leaking file descriptors + if parent process dies.

+

+ Own Id: OTP-12566

+
+ +

+ Add a new random number generator, see rand + module. It have better characteristics and an improved + interface.

+

+ Own Id: OTP-12586 Aux Id: OTP-12501, OTP-12502

+
+ +

filename:split/1 when given an empty binary + will now return an empty list, to make it consistent with + return value when given an empty list.

+

+ Own Id: OTP-12716

+
+
+
+ +
+
STDLIB 2.4
Fixed Bugs and Malfunctions -- cgit v1.2.3 From 9a81b28598fadc44bf506354c9227e41aac786f6 Mon Sep 17 00:00:00 2001 From: Henrik Nord Date: Wed, 13 May 2015 09:40:16 +0200 Subject: Revert "Prepare release" This reverts commit e09dd66dc4d89c62ddfd8c19791f9678d5d787c6. --- lib/stdlib/doc/src/notes.xml | 218 ------------------------------------------- 1 file changed, 218 deletions(-) (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/notes.xml b/lib/stdlib/doc/src/notes.xml index 3914a9bc0e..301a5ee2e8 100644 --- a/lib/stdlib/doc/src/notes.xml +++ b/lib/stdlib/doc/src/notes.xml @@ -30,224 +30,6 @@

This document describes the changes made to the STDLIB application.

-
STDLIB 2.5 - -
Fixed Bugs and Malfunctions - - -

- Fix handling of single dot in filename:join/2

-

- The reference manual says that filename:join(A,B) is - equivalent to filename:join([A,B]). In some rare cases - this turns out not to be true. For example:

-

- filename:join("/a/.","b") -> "/a/./b" vs - filename:join(["/a/.","b"]) -> "/a/b".

-

- This has been corrected. A single dot is now only kept if - it occurs at the very beginning or the very end of the - resulting path.

-

- *** POTENTIAL INCOMPATIBILITY ***

-

- Own Id: OTP-12158

-
- -

- The undocumented option generic_debug for - gen_server has been removed.

-

- Own Id: OTP-12183

-
- -

- erl_lint:icrt_export/4 has been rewritten to make the - code really follow the scoping rules of Erlang, and not - just in most situations by accident.

-

- Own Id: OTP-12186

-
- -

- Add 'trim_all' option to binary:split/3

-

- This option can be set to remove _ALL_ empty parts of the - result of a call to binary:split/3.

-

- Own Id: OTP-12301

-
- -

Correct orddict(3) regarding evaluation order of - fold() and map().

-

- Own Id: OTP-12651 Aux Id: seq12832

-
- -

- Correct maps module error exceptions

-

- Bad input to maps module function will now yield the - following exceptions: {badmap,NotMap} - or, badarg

-

- Own Id: OTP-12657

-
- -

- It is now possible to paste text in JCL mode (using - Ctrl-Y) that has been copied in the previous shell - session. Also a bug that caused the JCL mode to crash - when pasting text has been fixed.

-

- Own Id: OTP-12673

-
-
-
- - -
Improvements and New Features - - -

- Allow maps for supervisor flags and child specs

-

- Earlier, supervisor flags and child specs were given as - tuples. While this is kept for backwards compatibility, - it is now also allowed to give these parameters as maps, - see sup_flags - and child_spec.

-

- Own Id: OTP-11043

-
- -

- A new system message, terminate, is added. This - can be sent with sys:terminate/2,3. If the - receiving process handles system messages properly it - will terminate shortly after receiving this message.

-

- The new function proc_lib:stop/1,3 utilizes this - new system message and monitors the receiving process in - order to facilitate a synchronous stop mechanism for - 'special processes'.

-

- proc_lib:stop/1,3 is used by the following - functions:

-

- gen_server:stop/1,3 (new) - gen_fsm:stop/1,3 (new) - gen_event:stop/1,3 (modified to be - synchronous) wx_object:stop/1,3 - (new)

-

- Own Id: OTP-11173 Aux Id: seq12353

-
- -

- Remove the pg module, which has been deprecated - through OTP-17, is now removed from the STDLIB - application. This module has been marked experimental for - more than 15 years, and has largely been superseded by - the pg2 module from the Kernel application.

-

- Own Id: OTP-11907

-
- -

- New BIF: erlang:get_keys/0, lists all keys - associated with the process dictionary. Note: - erlang:get_keys/0 is auto-imported.

-

- *** POTENTIAL INCOMPATIBILITY ***

-

- Own Id: OTP-12151 Aux Id: seq12521

-
- -

Add three new functions to io_lib-- - scan_format/2, unscan_format/1, and - build_text/1-- which expose the parsed form of the - format control sequences to make it possible to easily - modify or filter the input to io_lib:format/2. - This can e.g. be used in order to replace unbounded-size - control sequences like ~w or ~p with - corresponding depth-limited ~W and ~P - before doing the actual formatting.

-

- Own Id: OTP-12167

-
- -

Introduce the erl_anno module, an abstraction - of the second element of tokens and tuples in the - abstract format.

-

- Own Id: OTP-12195

-
- -

- Support variables as Map keys in expressions and patterns

-

Erlang will accept any expression as keys in Map - expressions and it will accept literals or bound - variables as keys in Map patterns.

-

- Own Id: OTP-12218

-
- -

The last traces of Mnemosyne Rules have been removed. -

-

- Own Id: OTP-12257

-
- -

- Properly support maps in match_specs

-

- Own Id: OTP-12270

-
- -

- New function ets:take/2. Works the same as - ets:delete/2 but also returns the deleted - object(s).

-

- Own Id: OTP-12309

-
- -

string:tokens/2 is somewhat faster, especially - if the list of separators only contains one separator - character.

-

- Own Id: OTP-12422 Aux Id: seq12774

-
- -

- Prevent zip:zip_open/[12] from leaking file descriptors - if parent process dies.

-

- Own Id: OTP-12566

-
- -

- Add a new random number generator, see rand - module. It have better characteristics and an improved - interface.

-

- Own Id: OTP-12586 Aux Id: OTP-12501, OTP-12502

-
- -

filename:split/1 when given an empty binary - will now return an empty list, to make it consistent with - return value when given an empty list.

-

- Own Id: OTP-12716

-
-
-
- -
-
STDLIB 2.4
Fixed Bugs and Malfunctions -- cgit v1.2.3 From ddc4e717df1da722682b6ccdbf152a6b7e15f378 Mon Sep 17 00:00:00 2001 From: beaver Date: Wed, 25 Mar 2015 18:03:26 +0300 Subject: stdlib: Add gb_trees:iterator_from --- lib/stdlib/doc/src/gb_trees.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/gb_trees.xml b/lib/stdlib/doc/src/gb_trees.xml index b2f237e1d7..82167e1083 100644 --- a/lib/stdlib/doc/src/gb_trees.xml +++ b/lib/stdlib/doc/src/gb_trees.xml @@ -4,7 +4,7 @@
- 20012014 + 20012015 Ericsson AB. All Rights Reserved. @@ -182,6 +182,17 @@ memory at one time.

+ + + Return an iterator for a tree starting from specified key + +

Returns an iterator that can be used for traversing the + entries of Tree; see next/1. + The difference as compared to the iterator returned by + iterator/1 is that the first key greater than + or equal to Key is returned.

+
+
Return a list of the keys in a tree -- cgit v1.2.3 From f584a60d0e5a6fa0a8002a13e8dda2a790031427 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Tue, 12 May 2015 14:15:40 +0200 Subject: stdlib: Add gb_sets:iterator_from --- lib/stdlib/doc/src/gb_sets.xml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/gb_sets.xml b/lib/stdlib/doc/src/gb_sets.xml index ea96c14472..405bae5698 100644 --- a/lib/stdlib/doc/src/gb_sets.xml +++ b/lib/stdlib/doc/src/gb_sets.xml @@ -4,7 +4,7 @@
- 20012014 + 20012015 Ericsson AB. All Rights Reserved. @@ -305,6 +305,17 @@ memory at one time.

+ + + Return an iterator for a set starting from a specified element + +

Returns an iterator that can be used for traversing the + entries of Set; see next/1. + The difference as compared to the iterator returned by + iterator/1 is that the first element greater than + or equal to Element is returned.

+
+
Return largest element -- cgit v1.2.3 From fc1967b11a65690c9ea8274c7c7fda94f7a338fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Mon, 18 May 2015 10:19:24 +0200 Subject: stdlib: Document maps:filter/2 --- lib/stdlib/doc/src/maps.xml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/stdlib/doc/src') diff --git a/lib/stdlib/doc/src/maps.xml b/lib/stdlib/doc/src/maps.xml index e46068230a..7345a9357a 100644 --- a/lib/stdlib/doc/src/maps.xml +++ b/lib/stdlib/doc/src/maps.xml @@ -32,6 +32,28 @@ + + + Choose pairs which satisfy a predicate + +

+ Returns a map Map2 for which predicate + Pred holds true in Map1. +

+

+ The call will fail with a {badmap,Map} exception if + Map1 is not a map or with badarg if + Pred is not a function of arity 2. +

+

Example:

+ +> M = #{a => 2, b => 3, c=> 4, "a" => 1, "b" => 2, "c" => 4}, + Pred = fun(K,V) -> is_atom(K) andalso (V rem 2) =:= 0 end, + maps:filter(Pred,M). +#{a => 2,c => 4} +
+
+ -- cgit v1.2.3