Erlang Standard library Maps

Source: Internet
Author: User

new ()-#{}

Returns a new, empty mapping group.

1> maps:new ().

#{}

to_list (M), [{K1,v1}, ..., {KN,VN}]

Converts all keys and values in the mapping group M to a list of key values. The keys are sorted in ascending order in the generated list.

1> M = #{age = +, name + DMM}.

#{age = 18,name = DMM}

2> maps:to_list (M).

[{AGE,18},{NAME,DMM}]

From_list ([{k1,v1},..., {KN,VN}]), M

Converts a list of key-value pairs into a mapping group M. If the same key appears more than once, the last value associated with the list is used, and the preceding values are ignored.

1> T = [{age,18},{name,dmm},{age,19}].

[{age,18},{name,dmm},{age,19}]

2> maps:from_list (T).

#{age = 19,name = DMM}

size (Map), Integer () >= 0

Returns the number of entries in the Mapping group.

1> Map = #{42 = value_two,1337 = "Value One", "a" and "= 1}".

#{42 = value_two,1337 = "Value One", "a" and "= 1}"

2> maps:size (MAP).

3

Is_key (Key, MAP), BOOL ()

Returns true if the mapping group contains an entry with key keys, otherwise false is returned.

1> Map = #{"All" and "= value".

#{"+" = value}

2> Maps:is_key ("a", Map).

True

3> Maps:is_key (Value,map).

False

get (Key, Map), Val

Returns the value associated with the Key in the mapping group, or throws an exception error.

1> Map = #{42 = value_two,1337 = "Value One", "a" and "= 1}".

#{42 = value_two,1337 = "Value One", "a" and "= 1}"

2> Maps:get ("a", Map).

1

3> Maps:get (2,map).

* * Exception error: {badkey,2}

in function MAPS:GET/2

Called as maps:get (2,#{42 = value_two,1337 = "Value One", "a" and "= 1}")

get (Key, Map, Default), Value | Default

Returns the value associated with the key in the mapping group, and throws a default value if no key is available.

1> Map = #{Key1 = val1, Key2 = Val2}.

#{key1 = Val1,key2 = Val2}

2> Maps:get (Key1, Map, "Default value").

Val1

3> Maps:get (Key3, Map, "Default value").

"Default value"

Find (Key, Map), {OK, Value} | Error

Returns the value associated with the Key in the mapping group, otherwise returns an error.

1> Map = #{"Hi" = 42}.

#{"HI" = 42}

2> maps:find ("Hi", Map).

{ok,42}

3> maps:find ("HI", Map).

Error

keys (MAP), [Key1,.. KeyN]

Returns a list of the keys contained in the mapping group, sorted in ascending order.

1> Map = #{42 = value_three,1337 = "Value", "a" and "= 1}".

#{42 = value_three,1337 = "Value", "a" and "= 1}"

2> Maps:keys (MAP).

[42,1337, "a"]

Remove (Key, M), M1

Returns a new mapping group M1 except for keys that are key, except that the others are identical to M.

1> Map = #{"a" = 1}.

#{"A" = 1}

2> Maps:remove ("a", Map).

#{}

3> Maps:remove ("B", Map).

#{"A" = 1}

with ([Key1,.., KeyN], Map1), Map2

Returns a new mapping group MAP2, which is an assignment of MAP1, but has only the elements of these keys in the [Key1, ..., KeyN] list.

1> Map = #{42 = value_three,1337 = "Value", "a" and "= 1}".

#{42 = value_three,1337 = "Value", "a" and "= 1}"

2> Maps:with (["A", "a", "a", "other"],map).

#{42 = Value_three, "a" = 1}

without ([Key1,..., keyn],m), M1

Returns a new mapping group M1, which is a copy of M, except for the elements of these keys in the list with [Key1, ..., KeyN].

1> Map = #{42 = value_three,1337 = "Value", "a" and "= 1}".

#{42 = value_three,1337 = "Value", "a" and "= 1}"

2> Maps:without (["A", "a", "a", "other"],map).

#{1337 = "Value"}

Erlang Standard library Maps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.