You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many codes of the examples were not compilable.
Fixing it and adding some other unit tests so
some important properties not tested before are
validated
@@ -470,17 +485,18 @@ The solution used for this problems was 90% inspired in the [fraxken combine-asy
470
485
You can add custom methods to the FluentIterable and FluentAsyncIterable using the *extend* and *extendAsync* utilities. Here is a practical example of how to:
Copy file name to clipboardExpand all lines: advanced-examples/combining-sync-and-async-operations.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,8 +11,8 @@ fluentAsync(dataStream)
11
11
})
12
12
.map((x) =>requestSomeData(x)) // Here, request is an async operation
13
13
.map((x) =>otherRequest(parse(x))) // Parse is sync, otherRequest async, but that's okay, as long async/await is not used
14
-
.group('categoryId');// A grouping operation is performed by the categoryId value
15
-
take(10); //Take just 10 items
14
+
.group('categoryId') // A grouping operation is performed by the categoryId value
15
+
.take(10); //Take just 10 items
16
16
```
17
17
18
18
The good thing here is that fluent works over the iterable and async iterable mechanism, and in that way, it is possible to chain operations that results in promises, and all the iterable sequence will be respected, instead of generating a lot of promises which will flood node queue.
@@ -26,8 +26,8 @@ fluent(data)
26
26
})
27
27
.mapAsync((x) =>requestSomeData(x)) // From that point, the FluentIterable is transformed in a FluentAsyncIterable, and you don't need the async suffix any longer
28
28
.map((x) =>otherRequest(parse(x))) // Parse is sync, otherRequest async, but that's okay, as long async/await is not used
29
-
.group('categoryId');// A grouping operation is performed by the categoryId value
30
-
take(10); //Take just 10 items
29
+
.group('categoryId') // A grouping operation is performed by the categoryId value
Copy file name to clipboardExpand all lines: advanced-examples/nested-flattening-with-back-reference.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ fluent(invoices)
47
47
value: x.value
48
48
}))
49
49
)
50
-
)
50
+
);
51
51
```
52
52
53
53
Those nested fluent operation can become very messy when your business rule starts to become more complicated. Luckily, fluent offers you a powerful operation called **flatJoin**. With flatJoin, you can automatically obtain the items of each nested level with just one operation, like that:
@@ -59,7 +59,7 @@ fluent(invoices)
59
59
invoiceId: invoice.id,
60
60
itemId: items.id,
61
61
value: taxes.value
62
-
}))
62
+
}));
63
63
```
64
64
65
65
Look that the root item of each operation is added to the result in the property named with the symbol **tail**, that you can import from fluent. You can also get the last items from symbol **head**, but in this case it'll be the same value as the property **taxes**.
Copy file name to clipboardExpand all lines: advanced-examples/operators-and-resolvers.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ Instead, you need to do as follow:
26
26
```ts
27
27
const origin = [1, 2, 3];
28
28
const evens =fluent(it).filter((x) =>x%2===0);
29
-
const odds =fluent(it().filter((x) =>x%2!==0)
29
+
const odds =fluent(it).filter((x) =>x%2!==0)
30
30
```
31
31
32
32
That's how iterables works: you can't guarantee a second iteration over the same iterable, and that's needed for some core behaviors of it. Also, an iterable is not guaranteed to support multiples iterations over it. An array supports it, but it's not the rule, it's an exception. Iterables created using the [generator pattern](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator) can only be iterated once, for example. Because of this, fluent-iterable don't give support to parallel iterations deriving from the same node and must be used as a straight forward fluent tool.
@@ -44,7 +44,8 @@ The operations are executed in the chaining order for each iterable item when a
it('should keep an assured ascending order through filter and takeWhile operations, but not through a mapper when using assurer directly on iterable',()=>{
40
+
constit: any=fluent(o([1,2,3])).filter((x)=>x>1);
41
+
42
+
expect(it[orderAssured]).toBeDefined();
43
+
consttw=it.takeWhile((x: any)=>x<3);
44
+
45
+
expect(tw[orderAssured]).toBeDefined();
46
+
constmp: any=tw.map((x: any)=>x*2);
47
+
48
+
expect(mp[orderAssured]).not.toBeDefined();
49
+
});
39
50
it('should keep an assured descending order through filter and takeWhile operations, but not through a mapper',()=>{
0 commit comments