« Home » « Learn » « Download » « Github » ## Cello High Level C

### Methods

map

``````#define map(I, F)
``````

Construct a `Map` object on the stack over iterable `I` applying function `F`.

### Examples

Usage

``````var convert_to_int(var x) {
var y = new(Int);
look_from(y, x, 0);
return y;
}

var x = tuple(\$S("1"), \$S("2"), \$S("3"));

foreach (y in map(x, \$(Function, convert_to_int))) {
show(y); /* 1, 2, 3 */
};
``````

Usage 2

``````var print_object(var x) {
println("Object %\$ is of type %\$", x, type_of(x));
return NULL;
}

var x = tuple(\$I(0), \$S("Hello!"), \$F(2.4));

call(map(x, \$(Function, print_object)));
``````

# Map

Apply Function to Iterable

The `Map` type is an iterable that applies some callable to to each item in another iterable and returns the result. This can be useful to make more concise iteration when there are callback functions available.

If the mapping callable is a purely side-effect callable it is possible to use the `call` function on the `Map` object directly for a quick way to perform the iteration.

One downside of `Map` is that the `iter_type` becomes unknown (there is no way to know what type the callable will return so some objects such as `Array`s may revert to using `Ref` as the object type when assigned a `Map`.

### Definition

``````struct Map {
var iter;
var curr;
var func;
};
``````

### Derives

• Alloc`\$` `alloc` `dealloc`
• Assign`assign`
• Cast`cast`
• Cmp`cmp` `eq` `neq` `gt` `lt` `ge` `le`
• Copy`copy`
• Hash`hash` `hash_data`
• Size`size`
• Swap`swap`

### Implements

• Call`call`
• Doc`name` `brief` `description` `definition`
• Get`get` `set` `mem` `rem` `key_type` `val_type`
• Iter`foreach` `iter_init` `iter_next` `iter_type`
• Len`len`
• New`new` `del` `construct` `destruct`
{"ft_lang_label":"__label__en","ft_lang_prob":0.63891006,"math_prob":0.90842754,"size":1373,"snap":"2019-13-2019-22","text_gpt3_token_len":387,"char_repetition_ratio":0.11614317,"word_repetition_ratio":0.0,"special_character_ratio":0.28040788,"punctuation_ratio":0.1294964,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98265624,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-03-21T16:20:49Z\",\"WARC-Record-ID\":\"<urn:uuid:22da9e85-1b2f-4958-91b5-38e99f691639>\",\"Content-Length\":\"7253\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:16cda99d-6860-4d87-93b4-1e770225fd31>\",\"WARC-Concurrent-To\":\"<urn:uuid:f0432280-001a-449c-b828-8c1b29d1b828>\",\"WARC-IP-Address\":\"109.74.196.4\",\"WARC-Target-URI\":\"http://libcello.org/learn/map\",\"WARC-Payload-Digest\":\"sha1:CI6EBXVV3QD72PB3XB3HNAU7MXSMTAZO\",\"WARC-Block-Digest\":\"sha1:BPGTXVWULAN4B6DOQBM2H2E4RM45EPXL\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-13/CC-MAIN-2019-13_segments_1552912202526.24_warc_CC-MAIN-20190321152638-20190321174638-00385.warc.gz\"}"}