How to use the Iterable function from immutable

Find comprehensive JavaScript immutable.Iterable code examples handpicked from public code repositorys.

immutable.Iterable is a base interface for all immutable collection types in the Immutable.js library, providing methods for iterating over and manipulating collections.

123
124
125
126
127
128
129
130
131
132
133
134
	 */
	const fs 		= require('fs');
	/**
	 * @inheritdoc
	 */
	const isKeyed 	= Imm.Iterable.isKeyed;


	


/////////////////////////////////////////////////////////////////////////////////////////////
fork icon0
star icon1
watch icon2

+ 10 other calls in file

734
735
736
737
738
739
740
741
742
743
744
 *
 * If you wish to use it in the browser, please check out Browserify or WebPack!
 */


var Immutable = require('immutable');
var Iterable = Immutable.Iterable;
var Iterator = Iterable.Iterator;
var Seq = Immutable.Seq;
var Map = Immutable.Map;
var Record = Immutable.Record;
fork icon0
star icon1
watch icon0

+ 3 other calls in file

How does immutable.Iterable work?

immutable.Iterable is a data structure provided by the Immutable.js library that represents a collection of values that can be iterated over, but cannot be directly modified. Internally, an iterable is made up of a series of nodes that represent different segments of the collection, and it provides methods for creating modified versions of the iterable that share as much structure as possible with the original. These methods include functions for mapping, filtering, reducing, and flattening the iterable, as well as for concatenating it with other iterables, sorting it, and converting it to arrays or other formats.

11
12
13
14
15
16
17
18
19
20
21
 * @param {Array|List} arr
 * @param {Function(value, element, index)}
 * @return {Promise<Mixed>}
 */
function reduce(arr, iter, base) {
    arr = Immutable.Iterable.isIterable(arr)? arr : Immutable.List(arr);


    return arr.reduce(function(prev, elem, key) {
        return prev
        .then(function(val) {
fork icon0
star icon0
watch icon0

63
64
65
66
67
68
69
70
71
72
73
 */


var transformAccount = function transformAccount(account) {
    return (0, _immutable.fromJS)(account, function (key, value) {
        if (key === 'witness_votes') return value.toSet();
        var isIndexed = _immutable.Iterable.isIndexed(value);
        return isIndexed ? value.toList() : value.toOrderedMap();
    });
};

fork icon0
star icon0
watch icon0

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
const { Iterable } = require("immutable");

const list = Iterable([1, 2, 3, 4, 5]);

// Get the first item
const firstItem = list.first(); // 1

// Get the last item
const lastItem = list.last(); // 5

// Filter the list
const filteredList = list.filter((item) => item > 3); // Iterable [4, 5]

In this example, we import Iterable from the immutable library and create a new list containing the numbers 1 to 5. We then use the first and last methods to retrieve the first and last items of the list, respectively. Finally, we use the filter method to create a new list containing only the items that are greater than 3. Note that all of these operations return new immutable lists, leaving the original list unchanged.

19
20
21
22
23
24
25
26
27
28
    return fromJS(tree, function (key, value) {
      let outValue;
      if (key == 'value' && value.get(0) && value.get(0).toJS !== undefined)
        outValue = Immutable.List.of(value.get(0).toJS());
      else
        outValue = Immutable.Iterable.isIndexed(value) ? value.toList() : value.toOrderedMap();
      return outValue;
    });
};
initValue = '{"type":"group","id":"9a99988a-0123-4456-b89a-b1607f326fd8","children1":{"a98ab9b9-cdef-4012-b456-71607f326fd9":{"type":"rule","id":"a98ab9b9-cdef-4012-b456-71607f326fd9","properties":{"field":"multicolor","operator":"multiselect_equals","value":[["yellow","green"]],"valueSrc":["value"],"operatorOptions":null,"valueType":["multiselect"]},"path":["9a99988a-0123-4456-b89a-b1607f326fd8","a98ab9b9-cdef-4012-b456-71607f326fd9"]}},"properties":{"conjunction":"AND","not":false},"path":["9a99988a-0123-4456-b89a-b1607f326fd8"]}'
fork icon0
star icon0
watch icon0