Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
Added examples: sequenceEqual, findIndex, reduce, takeLast, skipLast
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Medeiros committed Aug 22, 2014
1 parent 9193d05 commit 81f532e
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 58 deletions.
8 changes: 7 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ DONE Added examples: sum, any, delayWithSelector
TODO Add more examples
TODO Render each stream with a different regular polygon
TODO Render also the stream completion time marker
TODO Disambiguate simultaneous marbles
Vertically spread them
Change example takeLast(1) to takeLast(2)
>>> v1.1.0

TODO Embeddable rxmarbles
- app.coffee 'exports' a function which can be called in <script> in index.html
app.coffee 'exports' a function which can be called in <script> in index.html
>>> v1.1.1

TODO Browser back button selects past operators
TODO Short text description of each operator, and link to official docs
>>> v1.2.0

Expand Down
194 changes: 158 additions & 36 deletions dist/js/app.js

Large diffs are not rendered by default.

25 changes: 15 additions & 10 deletions src/models/boolean-examples.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ module.exports = {
"apply": (inputs) -> inputs[0].contains({content:22}, (x,y) -> x.content == y.content)
}

# #TODO Debug and fix
# "sequenceEqual": {
# "label": "sequenceEqual"
# "isEmpty": {
# "label": "isEmpty"
# "inputs": [
# [{t:5, d:1}, {t:15, d:2}, {t:25, d:3}, {t:35, d:4}, {t:65, d:5}]
# [{t:2, d:1}, {t:20, d:2}, {t:40, d:3}, {t:70, d:4}, {t:77, d:5}]
# []
# ]
# "apply": (inputs) -> inputs[1].sequenceEqual(inputs[0], (x,y) ->
# return 1 if x.content > y.content
# return -1 if x.content < y.content
# return 0
# )
# "apply": (inputs) -> inputs[0].isEmpty()
# }

"sequenceEqual": {
"label": "sequenceEqual"
"inputs": [
[{t:5, d:1}, {t:15, d:2}, {t:25, d:3}, {t:35, d:4}, {t:65, d:5}]
[{t:2, d:1}, {t:20, d:2}, {t:40, d:3}, {t:70, d:4}, {t:77, d:5}]
]
"apply": (inputs) -> inputs[1].sequenceEqual(inputs[0], (x,y) ->
return (x.content == y.content)
)
}
}
20 changes: 18 additions & 2 deletions src/models/filter-examples.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@ module.exports = {
"apply": (inputs) -> inputs[0].skip(2)
}

"skipLast": {
"label": "skipLast(2)"
"inputs": [
[{t:30, d:1}, {t:40, d:2}, {t:65, d:3}, {t:75, d:4}]
]
"apply": (inputs) -> inputs[0].skipLast(2)
}

"skipUntil": {
"label": "skipUntil"
"inputs": [
[{t:0, d:1}, {t:10, d:2}, {t:20, d:3}, {t:30, d:4}, {t:40, d:5}, {t:50, d:6}, {t:60, d:7}, {t:70, d:8}, {t:80, d:9}]
[{t:47, d:0}, {t:73, d:0}]
[{t:45, d:0}, {t:73, d:0}]
]
"apply": (inputs) -> inputs[0].skipUntil(inputs[1])
}
Expand All @@ -82,11 +90,19 @@ module.exports = {
"apply": (inputs, scheduler) -> inputs[0].take(2, scheduler)
}

"takeLast": {
"label": "takeLast(1)"
"inputs": [
[{t:30, d:1}, {t:40, d:2}, {t:65, d:3}, {t:75, d:4}]
]
"apply": (inputs) -> inputs[0].takeLast(1)
}

"takeUntil": {
"label": "takeUntil"
"inputs": [
[{t:0, d:1}, {t:10, d:2}, {t:20, d:3}, {t:30, d:4}, {t:40, d:5}, {t:50, d:6}, {t:60, d:7}, {t:70, d:8}, {t:80, d:9}]
[{t:47, d:0}, {t:73, d:0}]
[{t:45, d:0}, {t:73, d:0}]
]
"apply": (inputs) -> inputs[0].takeUntil(inputs[1])
}
Expand Down
29 changes: 20 additions & 9 deletions src/models/math-examples.coffee
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
Rx = require 'rx'

module.exports = {
"aggregate": {
"label": "aggregate((x, y) => x + y)"
"inputs": [
[{t:5, d:1}, {t:15, d:2}, {t:25, d:3}, {t:35, d:4}, {t:65, d:5}]
]
"apply": (inputs) -> inputs[0].aggregate((x, y) ->
return {content: x.content + y.content, time: x.time, id: x.id+y.id}
)
}
# A clone of scan?
# "aggregate": {
# "label": "aggregate((x, y) => x + y)"
# "inputs": [
# [{t:5, d:1}, {t:15, d:2}, {t:25, d:3}, {t:35, d:4}, {t:65, d:5}]
# ]
# "apply": (inputs) -> inputs[0].aggregate((x, y) ->
# return {content: x.content + y.content, time: x.time, id: x.id+y.id}
# )
# }

"average": {
"label": "average"
Expand Down Expand Up @@ -51,6 +52,16 @@ module.exports = {
)
}

"reduce": {
"label": "reduce((x, y) => x + y)"
"inputs": [
[{t:5, d:1}, {t:15, d:2}, {t:25, d:3}, {t:35, d:4}, {t:65, d:5}]
]
"apply": (inputs) -> inputs[0].reduce((x, y) ->
return {content: x.content + y.content, time: x.time, id: x.id+y.id}
)
}

"sum": {
"label": "sum"
"inputs": [
Expand Down
8 changes: 8 additions & 0 deletions src/models/transform-examples.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ module.exports = {
)
}

"findIndex": {
"label": "findIndex(x => x > 10)"
"inputs": [
[{t:5, d:2}, {t:15, d:30}, {t:25, d:22}, {t:35, d:5}, {t:45, d:60}, {t:55, d:1}]
]
"apply": (inputs, scheduler) -> inputs[0].findIndex((x) -> x.content > 10)
}

"map": {
"label": "map(x => 10 * x)"
"inputs": [
Expand Down

0 comments on commit 81f532e

Please sign in to comment.