reacto 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +932 -11
- data/doc/reactive_programming_with_reacto.md +238 -0
- data/lib/reacto.rb +70 -0
- data/lib/reacto/behaviours.rb +24 -1
- data/lib/reacto/constants.rb +4 -1
- data/lib/reacto/executors.rb +8 -10
- data/lib/reacto/labeled_trackable.rb +14 -2
- data/lib/reacto/operations.rb +23 -2
- data/lib/reacto/operations/act.rb +69 -0
- data/lib/reacto/operations/append.rb +45 -0
- data/lib/reacto/operations/blocking_enumerable.rb +40 -0
- data/lib/reacto/operations/buffer.rb +1 -4
- data/lib/reacto/operations/chunk.rb +81 -0
- data/lib/reacto/operations/chunk_while.rb +56 -0
- data/lib/reacto/operations/cycle.rb +27 -0
- data/lib/reacto/operations/delay_each.rb +75 -0
- data/lib/reacto/operations/depend_on.rb +4 -5
- data/lib/reacto/operations/diff.rb +8 -10
- data/lib/reacto/operations/drop.rb +6 -8
- data/lib/reacto/operations/drop_while.rb +23 -0
- data/lib/reacto/operations/each_collect.rb +57 -0
- data/lib/reacto/operations/each_with_object.rb +31 -0
- data/lib/reacto/operations/extremums.rb +54 -0
- data/lib/reacto/operations/find_index.rb +28 -0
- data/lib/reacto/operations/flat_map.rb +2 -2
- data/lib/reacto/operations/flatten.rb +2 -7
- data/lib/reacto/operations/flatten_labeled.rb +44 -0
- data/lib/reacto/operations/{label.rb → group_by_label.rb} +1 -1
- data/lib/reacto/operations/include.rb +40 -0
- data/lib/reacto/operations/inject.rb +15 -9
- data/lib/reacto/operations/map.rb +15 -13
- data/lib/reacto/operations/merge.rb +17 -16
- data/lib/reacto/operations/operation_on_labeled.rb +29 -0
- data/lib/reacto/operations/partition.rb +52 -0
- data/lib/reacto/operations/prepend.rb +0 -3
- data/lib/reacto/operations/rescue_and_replace_error.rb +21 -0
- data/lib/reacto/operations/retry.rb +26 -0
- data/lib/reacto/operations/retry_when.rb +30 -0
- data/lib/reacto/operations/select.rb +2 -6
- data/lib/reacto/operations/slice.rb +50 -0
- data/lib/reacto/operations/slice_when.rb +41 -0
- data/lib/reacto/operations/split_labeled.rb +32 -0
- data/lib/reacto/operations/take.rb +9 -14
- data/lib/reacto/operations/take_while.rb +28 -0
- data/lib/reacto/operations/throttle.rb +2 -3
- data/lib/reacto/operations/track_on.rb +1 -3
- data/lib/reacto/shared_trackable.rb +2 -5
- data/lib/reacto/subscriptions/buffered_subscription.rb +10 -9
- data/lib/reacto/subscriptions/executor_subscription.rb +12 -4
- data/lib/reacto/subscriptions/tracker_subscription.rb +0 -4
- data/lib/reacto/subscriptions/zipping_subscription.rb +0 -1
- data/lib/reacto/trackable.rb +429 -64
- data/lib/reacto/version.rb +1 -1
- data/reacto.gemspec +2 -3
- data/spec/reacto/labeled_trackable_spec.rb +17 -0
- data/spec/reacto/trackable/act_spec.rb +15 -0
- data/spec/reacto/trackable/all_spec.rb +38 -0
- data/spec/reacto/trackable/any_spec.rb +39 -0
- data/spec/reacto/trackable/append_spec.rb +38 -0
- data/spec/reacto/trackable/buffer_spec.rb +11 -15
- data/spec/reacto/trackable/chunk_spec.rb +86 -0
- data/spec/reacto/trackable/chunk_while_spec.rb +22 -0
- data/spec/reacto/trackable/class_level/combine_last_spec.rb +1 -3
- data/spec/reacto/trackable/class_level/interval_spec.rb +4 -6
- data/spec/reacto/trackable/class_level/make_spec.rb +0 -15
- data/spec/reacto/trackable/{zip_spec.rb → class_level/zip_spec.rb} +0 -2
- data/spec/reacto/trackable/concat_spec.rb +12 -12
- data/spec/reacto/trackable/count_spec.rb +38 -0
- data/spec/reacto/trackable/cycle_spec.rb +14 -0
- data/spec/reacto/trackable/delay_each_spec.rb +18 -0
- data/spec/reacto/trackable/depend_on_spec.rb +6 -9
- data/spec/reacto/trackable/diff_spec.rb +3 -5
- data/spec/reacto/trackable/drop_errors_spec.rb +1 -3
- data/spec/reacto/trackable/drop_while_spec.rb +15 -0
- data/spec/reacto/trackable/each_cons_spec.rb +53 -0
- data/spec/reacto/trackable/each_slice_spec.rb +37 -0
- data/spec/reacto/trackable/each_with_index_spec.rb +33 -0
- data/spec/reacto/trackable/each_with_object_spec.rb +26 -0
- data/spec/reacto/trackable/entries_spec.rb +25 -0
- data/spec/reacto/trackable/execute_on_spec.rb +33 -0
- data/spec/reacto/trackable/find_index_spec.rb +31 -0
- data/spec/reacto/trackable/find_spec.rb +34 -0
- data/spec/reacto/trackable/first_spec.rb +36 -0
- data/spec/reacto/trackable/flat_map_latest_spec.rb +5 -5
- data/spec/reacto/trackable/flat_map_spec.rb +25 -0
- data/spec/reacto/trackable/flatten_labeled_spec.rb +48 -0
- data/spec/reacto/trackable/grep_spec.rb +29 -0
- data/spec/reacto/trackable/grep_v_spec.rb +23 -0
- data/spec/reacto/trackable/{label_spec.rb → group_by_label_spec.rb} +4 -11
- data/spec/reacto/trackable/include_spec.rb +23 -0
- data/spec/reacto/trackable/inject_spec.rb +30 -4
- data/spec/reacto/trackable/lift_spec.rb +1 -3
- data/spec/reacto/trackable/map_spec.rb +17 -3
- data/spec/reacto/trackable/max_by_spec.rb +12 -0
- data/spec/reacto/trackable/max_spec.rb +19 -0
- data/spec/reacto/trackable/merge_spec.rb +6 -7
- data/spec/reacto/trackable/min_by_spec.rb +12 -0
- data/spec/reacto/trackable/min_spec.rb +19 -0
- data/spec/reacto/trackable/minmax_by_spec.rb +12 -0
- data/spec/reacto/trackable/minmax_spec.rb +19 -0
- data/spec/reacto/trackable/none_spec.rb +38 -0
- data/spec/reacto/trackable/on_spec.rb +11 -4
- data/spec/reacto/trackable/one_spec.rb +38 -0
- data/spec/reacto/trackable/partition_spec.rb +23 -0
- data/spec/reacto/trackable/prepend_spec.rb +1 -3
- data/spec/reacto/trackable/reject_spec.rb +21 -0
- data/spec/reacto/trackable/rescue_and_replace_error_spec.rb +48 -0
- data/spec/reacto/trackable/rescue_and_replace_error_with_spec.rb +26 -0
- data/spec/reacto/trackable/retry_spec.rb +50 -0
- data/spec/reacto/trackable/retry_when_spec.rb +33 -0
- data/spec/reacto/trackable/select_spec.rb +18 -7
- data/spec/reacto/trackable/slice_after_spec.rb +38 -0
- data/spec/reacto/trackable/slice_before_spec.rb +38 -0
- data/spec/reacto/trackable/slice_when_spec.rb +26 -0
- data/spec/reacto/trackable/sort_by_spec.rb +16 -0
- data/spec/reacto/trackable/sort_spec.rb +23 -0
- data/spec/reacto/trackable/split_labeled_spec.rb +37 -0
- data/spec/reacto/trackable/take_while_spec.rb +16 -0
- data/spec/reacto/trackable/throttle_spec.rb +2 -3
- data/spec/reacto/trackable/track_on_spec.rb +2 -3
- data/spec/reacto/trackable/uniq_spec.rb +2 -4
- data/spec/support/helpers.rb +9 -1
- metadata +135 -25
- data/Gemfile.lock +0 -32
- data/lib/reacto/operations/cache.rb +0 -53
- data/spec/reacto/trackable/cache_spec.rb +0 -64
@@ -0,0 +1,36 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#first' do
|
3
|
+
subject(:test_source) { described_class.enumerable((1..100)) }
|
4
|
+
|
5
|
+
it 'emits only the first element emitted by the source' do
|
6
|
+
trackable = test_source.first
|
7
|
+
|
8
|
+
attach_test_trackers(trackable)
|
9
|
+
|
10
|
+
expect(test_data).to eq([1, '|'])
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'emits only the first <n> element emitted by the source ' \
|
14
|
+
'if <n> is given' do
|
15
|
+
trackable = test_source.first(5)
|
16
|
+
|
17
|
+
attach_test_trackers(trackable)
|
18
|
+
|
19
|
+
expect(test_data).to eq([1, 2, 3, 4, 5, '|'])
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'raises an ArgumentError if <n> is given and is bellow zero' do
|
23
|
+
expect do
|
24
|
+
test_data.first(-2)
|
25
|
+
end.to raise_error(ArgumentError).with_message('negative array size')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'emits only the close notification if <n> is given and is zero' do
|
29
|
+
trackable = test_source.first(0)
|
30
|
+
|
31
|
+
attach_test_trackers(trackable)
|
32
|
+
|
33
|
+
expect(test_data).to eq(['|'])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
context Reacto::Trackable do
|
4
|
-
context 'flat_map_latest' do
|
5
|
-
it '
|
2
|
+
context '#flat_map_latest' do
|
3
|
+
it 'emits the elements of the first returned Trackable from the block ' \
|
4
|
+
'until the block returns the next one. Then it switches to emitting ' \
|
5
|
+
'from the next' do
|
6
6
|
trackable = described_class.interval(1).take(3).flat_map_latest do |val|
|
7
7
|
Reacto::Trackable.interval(0.3, (val..7).to_enum)
|
8
8
|
end
|
@@ -12,7 +12,7 @@ context Reacto::Trackable do
|
|
12
12
|
)
|
13
13
|
|
14
14
|
trackable.await(subscription)
|
15
|
-
expect(test_data).to
|
15
|
+
expect(test_data).to eq([0, 1, 2, 1, 2, 3, 2, 3, 4, 5, 6, 7, '|'])
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -14,5 +14,30 @@ context Reacto::Trackable do
|
|
14
14
|
)
|
15
15
|
expect(test_data).to be == [1, 2, 2, 3, 3, 4, 4, 5, 5, 6, '|']
|
16
16
|
end
|
17
|
+
|
18
|
+
context 'with label' do
|
19
|
+
it 'applies the transformation passed only to the values of ' \
|
20
|
+
'the incoming values of type LabeledTrackable with matching label' do
|
21
|
+
trackable =
|
22
|
+
Reacto::Trackable.enumerable((1..10).each).group_by_label do |value|
|
23
|
+
[(value % 3), value]
|
24
|
+
end
|
25
|
+
|
26
|
+
trackable = trackable.flat_map(label: 1) do |value|
|
27
|
+
Reacto::Trackable.enumerable((value..10))
|
28
|
+
end
|
29
|
+
|
30
|
+
trackable.on(value: test_on_value)
|
31
|
+
|
32
|
+
labeled_trackable = test_data.first
|
33
|
+
expect(labeled_trackable.label).to eq(1)
|
34
|
+
|
35
|
+
labeled_data = []
|
36
|
+
labeled_trackable.on(value: ->(v) { labeled_data << v })
|
37
|
+
|
38
|
+
expected = [(1..10), (4..10), (7..10)].map(&:to_a).flatten + [10]
|
39
|
+
expect(labeled_data).to eq(expected)
|
40
|
+
end
|
41
|
+
end
|
17
42
|
end
|
18
43
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#flatten_labeled' do
|
3
|
+
it 'transfomrs the LabeledTrackable instances emitted into objects with' \
|
4
|
+
'two attributes - label the label of the LabeledTrackable and value -' \
|
5
|
+
'the first value of emitted by the LabeledTrackable' do
|
6
|
+
trackable = described_class.enumerable((1..10)).group_by_label do |value|
|
7
|
+
[(value % 3), value]
|
8
|
+
end
|
9
|
+
trackable = trackable.flatten_labeled
|
10
|
+
|
11
|
+
trackable.on(value: test_on_value)
|
12
|
+
|
13
|
+
expect(test_data.count).to eq(3)
|
14
|
+
expect(test_data.map(&:value)).to eq([1, 2, 3])
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'transfomrs the LabeledTrackable instances emitted into objects with' \
|
18
|
+
'two attributes - label the label of the LabeledTrackable and value -' \
|
19
|
+
'the last value computed by the passed accumulator block' do
|
20
|
+
trackable = described_class.enumerable((1..10)).group_by_label do |value|
|
21
|
+
[(value % 3), value]
|
22
|
+
end
|
23
|
+
trackable = trackable.flatten_labeled { |prev, curr| prev + curr }
|
24
|
+
|
25
|
+
trackable.on(value: test_on_value)
|
26
|
+
|
27
|
+
expect(test_data.count).to eq(3)
|
28
|
+
expect(test_data.map(&:value)).to eq([22, 15, 18])
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'transfomrs the LabeledTrackable instances emitted into objects with' \
|
32
|
+
'two attributes - label the label of the LabeledTrackable and value -' \
|
33
|
+
'the last value computed by the passed accumulator block, using the ' \
|
34
|
+
'passed initial value' do
|
35
|
+
trackable = described_class.enumerable((1..10)).group_by_label do |value|
|
36
|
+
[(value % 3), value]
|
37
|
+
end
|
38
|
+
trackable = trackable.flatten_labeled(initial: -10) do |prev, curr|
|
39
|
+
prev + curr
|
40
|
+
end
|
41
|
+
|
42
|
+
trackable.on(value: test_on_value)
|
43
|
+
|
44
|
+
expect(test_data.count).to eq(3)
|
45
|
+
expect(test_data.map(&:value)).to eq([12, 5, 8])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#grep' do
|
3
|
+
subject(:test_source) { described_class.enumerable((1..100)) }
|
4
|
+
|
5
|
+
it 'returns a Reacto::Trackable emitting every value emitted by the ' \
|
6
|
+
'source for which the given <pattern> === value' do
|
7
|
+
trackable = test_source.grep(38..44)
|
8
|
+
|
9
|
+
attach_test_trackers(trackable)
|
10
|
+
|
11
|
+
expect(test_data).to eq([38, 39, 40, 41, 42, 43, 44, '|'])
|
12
|
+
end
|
13
|
+
|
14
|
+
subject(:test_source2) do
|
15
|
+
described_class.enumerable([
|
16
|
+
'HEY', 'FIND_ME', 'YO', 'FIND_HER', 'FIND_IT', 'FOUND_ME', 'NO_WAY'
|
17
|
+
])
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'passes each matching value to the optional block, if supplied and ' \
|
21
|
+
'the reuslts from it are emitted' do
|
22
|
+
trackable = test_source2.grep(/FIND/) { |v| v[-1] }
|
23
|
+
|
24
|
+
attach_test_trackers(trackable)
|
25
|
+
|
26
|
+
expect(test_data).to eq(%w(E R T |))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#grep_v' do
|
3
|
+
subject(:test_source) { described_class.enumerable((1..10)) }
|
4
|
+
|
5
|
+
it 'returns a Reacto::Trackable emitting every value emitted by the ' \
|
6
|
+
'source for which the given <pattern> === value returns false' do
|
7
|
+
trackable = test_source.grep_v(2..5)
|
8
|
+
|
9
|
+
attach_test_trackers(trackable)
|
10
|
+
|
11
|
+
expect(test_data).to eq([1, 6, 7, 8, 9, 10, '|'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'passes each not matching value to the optional block, if supplied ' \
|
15
|
+
'and the reuslts from it are emitted' do
|
16
|
+
trackable = test_source.grep_v(2..7) { |v| v.even? }
|
17
|
+
|
18
|
+
attach_test_trackers(trackable)
|
19
|
+
|
20
|
+
expect(test_data).to eq([false, true, false, true, '|'])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
context Reacto::Trackable do
|
2
|
-
context '#
|
2
|
+
context '#group_by_label' do
|
3
3
|
it 'transforms each of the values emitted by the source into ' \
|
4
4
|
'LabeledTrackable instances, using the passed function to get their ' \
|
5
5
|
'labels and values to emit' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
trackable = described_class.enumerable((1..10)).group_by_label do |value|
|
7
|
+
[(value % 3), value]
|
8
|
+
end
|
10
9
|
|
11
10
|
trackable.on(value: test_on_value)
|
12
11
|
|
@@ -24,12 +23,6 @@ context Reacto::Trackable do
|
|
24
23
|
two.on(value: ->(v) { two_array << v })
|
25
24
|
expect(two_array).to eq([2, 5, 8])
|
26
25
|
|
27
|
-
two = test_data[1]
|
28
|
-
expect(two.label).to eq(2)
|
29
|
-
two_array = []
|
30
|
-
two.on(value: ->(v) { two_array << v })
|
31
|
-
expect(two_array).to eq([2, 5, 8])
|
32
|
-
|
33
26
|
zero = test_data.last
|
34
27
|
expect(zero.label).to eq(0)
|
35
28
|
zero_array = []
|
@@ -0,0 +1,23 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
context '#include?' do
|
3
|
+
subject(:test_source) { described_class.enumerable((1..10)) }
|
4
|
+
|
5
|
+
it 'it creates a Reacto::Trackable emitting only one value : `true` if ' \
|
6
|
+
'the object given is emitted by the source' do
|
7
|
+
trackable = test_source.include?(5)
|
8
|
+
|
9
|
+
attach_test_trackers(trackable)
|
10
|
+
|
11
|
+
expect(test_data).to eq([true, '|'])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'it creates a Reacto::Trackable emitting only one value : `false` if ' \
|
15
|
+
'the object given is not emitted by the source' do
|
16
|
+
trackable = test_source.include?(15)
|
17
|
+
|
18
|
+
attach_test_trackers(trackable)
|
19
|
+
|
20
|
+
expect(test_data).to eq([false, '|'])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
context Reacto::Trackable do
|
4
2
|
context '#inject' do
|
5
3
|
let(:test_behaviour) do
|
@@ -23,6 +21,18 @@ context Reacto::Trackable do
|
|
23
21
|
expect(test_data).to be == [16, 23, 2037]
|
24
22
|
end
|
25
23
|
|
24
|
+
it 'keeps the same results for multiple subscriptions' do
|
25
|
+
trackable = source.inject(0) do |prev, v|
|
26
|
+
prev + v
|
27
|
+
end
|
28
|
+
trackable.on(value: test_on_value)
|
29
|
+
trackable.on(value: test_on_value)
|
30
|
+
trackable.on(value: test_on_value)
|
31
|
+
|
32
|
+
expect(test_data.size).to be(9)
|
33
|
+
expect(test_data).to be == [16, 23, 2037] * 3
|
34
|
+
end
|
35
|
+
|
26
36
|
it 'sends the values created by applying the `inject` operation on the ' \
|
27
37
|
'last value and current value, using for first value ' \
|
28
38
|
'the first emitted by the source if no initial value provided' do
|
@@ -36,7 +46,7 @@ context Reacto::Trackable do
|
|
36
46
|
end
|
37
47
|
|
38
48
|
it 'sends the initial value if no value is emitted' do
|
39
|
-
source = described_class.new(
|
49
|
+
source = described_class.new(&-> (t) { t.on_close })
|
40
50
|
trackable = source.inject(0) do |prev, v|
|
41
51
|
prev + v
|
42
52
|
end
|
@@ -47,7 +57,7 @@ context Reacto::Trackable do
|
|
47
57
|
end
|
48
58
|
|
49
59
|
it 'sends nothing if no initial value and no value emitted' do
|
50
|
-
source = described_class.new(
|
60
|
+
source = described_class.new(&-> (t) { t.on_close })
|
51
61
|
trackable = source.inject do |prev, v|
|
52
62
|
prev + v
|
53
63
|
end
|
@@ -55,5 +65,21 @@ context Reacto::Trackable do
|
|
55
65
|
|
56
66
|
expect(test_data.size).to be(0)
|
57
67
|
end
|
68
|
+
|
69
|
+
context 'with label' do
|
70
|
+
it 'applies the accumulation only to the emitted values of type ' \
|
71
|
+
'LabeledTrackable with the matching label' do
|
72
|
+
source = described_class.enumerable((1..10)).group_by_label do |value|
|
73
|
+
[(value % 3), value]
|
74
|
+
end
|
75
|
+
|
76
|
+
trackable = source.inject(12, label: 0) { |prev, curr| prev + curr }
|
77
|
+
trackable.on(value: test_on_value)
|
78
|
+
|
79
|
+
expect_trackable_values(test_data.first, [1, 4, 7, 10], label: 1)
|
80
|
+
expect_trackable_values(test_data[1], [2, 5, 8], label: 2)
|
81
|
+
expect_trackable_values(test_data.last, [15, 21, 30], label: 0)
|
82
|
+
end
|
83
|
+
end
|
58
84
|
end
|
59
85
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
context Reacto::Trackable do
|
4
2
|
context '#lift' do
|
5
3
|
it 'applies a transformation to the trackable behaviour' do
|
@@ -13,7 +11,7 @@ context Reacto::Trackable do
|
|
13
11
|
lifted_trackable.on(value: test_on_value)
|
14
12
|
|
15
13
|
expect(test_data.size).to be(1)
|
16
|
-
expect(test_data
|
14
|
+
expect(test_data.first).to be(25)
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
@@ -17,7 +17,7 @@ context Reacto::Trackable do
|
|
17
17
|
subscriber.on_value(4)
|
18
18
|
subscriber.on_error(StandardError.new('error'))
|
19
19
|
end
|
20
|
-
trackable = source.map(-> (
|
20
|
+
trackable = source.map(error: -> (e) { 5 }, &-> (v) { v })
|
21
21
|
|
22
22
|
trackable.on(value: test_on_value, error: test_on_error)
|
23
23
|
|
@@ -28,11 +28,25 @@ context Reacto::Trackable do
|
|
28
28
|
it 'emits what is produced by the passed `close` function before close' do
|
29
29
|
trackable =
|
30
30
|
described_class.enumerable((1..5)).map(close: ->() { 10 }) do |v|
|
31
|
-
|
31
|
+
v
|
32
32
|
end
|
33
33
|
|
34
34
|
trackable.on(value: test_on_value, close: test_on_close)
|
35
|
-
expect(test_data).to
|
35
|
+
expect(test_data).to eq((1..5).to_a + [10, '|'])
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with label' do
|
39
|
+
it 'applies the mapping passed only to the incoming values of type ' \
|
40
|
+
'LabeledTrackable with the matching label' do
|
41
|
+
source = described_class.enumerable((1..10)).group_by_label do |value|
|
42
|
+
[(value % 3), value]
|
43
|
+
end
|
44
|
+
|
45
|
+
trackable = source.map(label: 1, close: -> { 4 }) { |value| value / 3 }
|
46
|
+
trackable.on(value: test_on_value)
|
47
|
+
|
48
|
+
expect_trackable_values(test_data.first, [0, 1, 2, 3, 4], label: 1)
|
49
|
+
end
|
36
50
|
end
|
37
51
|
end
|
38
52
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
subject(:source) { described_class.enumerable(%w(albatross dog horse snake)) }
|
3
|
+
|
4
|
+
context '#max_by' do
|
5
|
+
it 'emits the value emitted by source that gives the maximum value from ' \
|
6
|
+
'the given block. ' do
|
7
|
+
attach_test_trackers(source.max_by { |val| val.size })
|
8
|
+
|
9
|
+
expect(test_data).to eq(%w(albatross |))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
subject(:source) { described_class.enumerable(%w(albatross dog horse snake)) }
|
3
|
+
|
4
|
+
context '#max' do
|
5
|
+
it 'emits the maximum value emitted by source assuming that all the ' \
|
6
|
+
'values implement Comparable' do
|
7
|
+
attach_test_trackers(source.max)
|
8
|
+
|
9
|
+
expect(test_data).to eq(%w(snake |))
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'emits the maximum value emitted by source using the block given to ' \
|
13
|
+
'compare the values ' do
|
14
|
+
attach_test_trackers(source.max { |val1, val2| val1.size <=> val2.size })
|
15
|
+
|
16
|
+
expect(test_data).to eq(%w(albatross |))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
context Reacto::Trackable do
|
4
2
|
context '#merge' do
|
5
3
|
it 'merges the passed trackable\'s emitions with the source ones' do
|
@@ -12,8 +10,9 @@ context Reacto::Trackable do
|
|
12
10
|
)
|
13
11
|
trackable.await(subscription)
|
14
12
|
|
15
|
-
expect(test_data).to
|
16
|
-
[
|
13
|
+
expect(test_data).to eq(
|
14
|
+
['0a', '0b', '1a', '2a', '1b', '3a', '4a', '2b', '3b', '|']
|
15
|
+
)
|
17
16
|
end
|
18
17
|
|
19
18
|
it 'finishes with the error if `delay_error` is true' do
|
@@ -32,9 +31,9 @@ context Reacto::Trackable do
|
|
32
31
|
)
|
33
32
|
trackable.await(subscription, 2)
|
34
33
|
|
35
|
-
expect(test_data).to
|
36
|
-
[
|
37
|
-
|
34
|
+
expect(test_data).to eq(
|
35
|
+
['0a', '0b', '1a', '2a', '1b', '2b', '3b', err]
|
36
|
+
)
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
context Reacto::Trackable do
|
2
|
+
subject(:source) { described_class.enumerable(%w(albatross dog horse snake)) }
|
3
|
+
|
4
|
+
context '#min_by' do
|
5
|
+
it 'emits the value emitted by source that gives the minimum value from ' \
|
6
|
+
'the given block. ' do
|
7
|
+
attach_test_trackers(source.min_by { |val| val.size })
|
8
|
+
|
9
|
+
expect(test_data).to eq(%w(dog |))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|