├── .gitignore ├── MIT-LICENSE.txt ├── README.md ├── bower.json ├── generated-docs └── RxJS │ ├── AsyncSubject.md │ ├── BehaviorSubject.md │ ├── Notification.md │ ├── Observable.md │ ├── ReplaySubject.md │ ├── Scheduler.md │ ├── Subscriber.md │ └── Subscription.md ├── index.html ├── package.json ├── src ├── RxJS │ ├── AsyncSubject.js │ ├── AsyncSubject.purs │ ├── BehaviorSubject.js │ ├── BehaviorSubject.purs │ ├── Notification.purs │ ├── Observable.js │ ├── Observable.purs │ ├── ReplaySubject.js │ ├── ReplaySubject.purs │ ├── Scheduler.js │ ├── Scheduler.purs │ ├── Subscriber.purs │ ├── Subscription.js │ └── Subscription.purs └── entry.js ├── test └── Main.purs └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | /bower_components/ 2 | /node_modules/ 3 | /.pulp-cache/ 4 | /output/ 5 | /.psc* 6 | /.psa* 7 | /yarn.lock 8 | /src/Main.purs 9 | /npm-debug.log 10 | -------------------------------------------------------------------------------- /MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 2 | 3 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # purescript-rxjs 2 | An un-opinionated PureScript wrapper for RxJS. 3 | 4 | 5 | ### Installation 6 | 7 | ```bash 8 | npm install rxjs 9 | bower install purescript-rxjs 10 | ``` 11 | 12 | ### Documentation 13 | 14 | - See the `docs` folder. 15 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "purescript-rxjs", 3 | "ignore": [ 4 | "**/.*", 5 | "node_modules", 6 | "bower_components", 7 | "output" 8 | ], 9 | "dependencies": { 10 | "purescript-prelude": "^3.0.0", 11 | "purescript-console": "^3.0.0", 12 | "purescript-functions": "^3.0.0", 13 | "purescript-exceptions": "^3.0.0", 14 | "purescript-aff": "^3.0.0", 15 | "purescript-arrays": "^4.0.0", 16 | "purescript-st": "^3.0.0", 17 | "purescript-dom": "^4.1.0", 18 | "purescript-maps" : "^3.0.0" 19 | }, 20 | "devDependencies": { 21 | "purescript-psci-support": "^3.0.0", 22 | "purescript-debug": "^3.0.0", 23 | "purescript-test-unit": "^11.0.0", 24 | "purescript-quickcheck": "^4.0.0" 25 | }, 26 | "license": "MIT", 27 | "repository": { 28 | "type": "git", 29 | "url": "git://github.com/jasonzoladz/purescript-rxjs.git" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /generated-docs/RxJS/AsyncSubject.md: -------------------------------------------------------------------------------- 1 | ## Module RxJS.AsyncSubject 2 | 3 | #### `AsyncSubject` 4 | 5 | ``` purescript 6 | data AsyncSubject :: Type -> Type 7 | ``` 8 | 9 | Please see [RxJS Version 5.* documentation](http://reactivex.io/rxjs/) for 10 | additional details on proper usage of the library. 11 | 12 | ##### Instances 13 | ``` purescript 14 | Functor AsyncSubject 15 | Apply AsyncSubject 16 | Applicative AsyncSubject 17 | Bind AsyncSubject 18 | Monad AsyncSubject 19 | Semigroup (AsyncSubject a) 20 | Alt AsyncSubject 21 | Plus AsyncSubject 22 | Alternative AsyncSubject 23 | MonadZero AsyncSubject 24 | MonadPlus AsyncSubject 25 | ``` 26 | 27 | #### `observeOn` 28 | 29 | ``` purescript 30 | observeOn :: forall a. Scheduler -> AsyncSubject a -> AsyncSubject a 31 | ``` 32 | 33 | Makes every `next` call run in the new Scheduler. 34 | 35 | #### `subscribeOn` 36 | 37 | ``` purescript 38 | subscribeOn :: forall a. Scheduler -> AsyncSubject a -> AsyncSubject a 39 | ``` 40 | 41 | Makes subscription happen on a given Scheduler. 42 | 43 | #### `subscribe` 44 | 45 | ``` purescript 46 | subscribe :: forall a e. Subscriber a -> AsyncSubject a -> Eff e Subscription 47 | ``` 48 | 49 | Subscribing to an AsyncSubject is like calling a function, providing 50 | `next`, `error` and `completed` effects to which the data will be delivered. 51 | 52 | #### `subscribeNext` 53 | 54 | ``` purescript 55 | subscribeNext :: forall a e. (a -> Eff e Unit) -> AsyncSubject a -> Eff e Subscription 56 | ``` 57 | 58 | #### `just` 59 | 60 | ``` purescript 61 | just :: forall a. a -> AsyncSubject a 62 | ``` 63 | 64 | Creates an AsyncSubject that emits the value specify, 65 | and then emits a complete notification. An alias for `of`. 66 | 67 | #### `asObservable` 68 | 69 | ``` purescript 70 | asObservable :: forall a. AsyncSubject a -> Observable a 71 | ``` 72 | 73 | Create an Observable from a AsyncSubject 74 | 75 | #### `buffer` 76 | 77 | ``` purescript 78 | buffer :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject (Array a) 79 | ``` 80 | 81 | Collects values from the first AsyncSubject into an Array, and emits that array only when 82 | second AsyncSubject emits. 83 | 84 | #### `bufferCount` 85 | 86 | ``` purescript 87 | bufferCount :: forall a. Int -> Int -> AsyncSubject a -> AsyncSubject (Array a) 88 | ``` 89 | 90 | Collects values from the past as an array, emits that array when 91 | its size (arg1) reaches the specified buffer size, and starts a new buffer. 92 | The new buffer starts with nth (arg2) element of the AsyncSubject counting 93 | from the beginning of the *last* buffer. 94 | 95 | #### `bufferToggle` 96 | 97 | ``` purescript 98 | bufferToggle :: forall a b c. (AsyncSubject a) -> (AsyncSubject b) -> (b -> AsyncSubject c) -> (AsyncSubject (Array a)) 99 | ``` 100 | 101 | Collects values from the source AsyncSubject (arg1) as an array. Starts collecting only when 102 | the opening (arg2) AsyncSubject emits, and calls the closingSelector function (arg3) to get an AsyncSubject 103 | that decides when to close the buffer. Another buffer opens when the 104 | opening AsyncSubject emits its next value. 105 | 106 | #### `bufferWhen` 107 | 108 | ``` purescript 109 | bufferWhen :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject (Array a) 110 | ``` 111 | 112 | Collects values from the past as an array. When it starts collecting values, 113 | it calls a function that returns an AsyncSubject that emits to close the 114 | buffer and restart collecting. 115 | 116 | #### `concatMap` 117 | 118 | ``` purescript 119 | concatMap :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject b 120 | ``` 121 | 122 | Equivalent to mergeMap (a.k.a, `>>=`) EXCEPT that, unlike mergeMap, 123 | the next bind will not run until the AsyncSubject generated by the projection function (arg2) 124 | completes. That is, composition is sequential, not concurrent. 125 | Warning: if source values arrive endlessly and faster than their corresponding 126 | inner AsyncSubjects can complete, it will result in memory issues as inner 127 | AsyncSubjects amass in an unbounded buffer waiting for their turn to be subscribed to. 128 | 129 | #### `concatMapTo` 130 | 131 | ``` purescript 132 | concatMapTo :: forall a b c. AsyncSubject a -> AsyncSubject b -> (a -> b -> AsyncSubject c) -> AsyncSubject c 133 | ``` 134 | 135 | The type signature explains it best. Warning: Like `concatMap`, composition is sequential. 136 | 137 | #### `every` 138 | 139 | ``` purescript 140 | every :: forall a. AsyncSubject a -> (a -> Boolean) -> AsyncSubject Boolean 141 | ``` 142 | 143 | Determines whether all elements of an AsyncSubject satisfy a condition. 144 | Returns an AsyncSubject containing a single element determining whether all 145 | elements in the source AsyncSubject pass the test in the specified predicate. 146 | 147 | #### `exhaustMap` 148 | 149 | ``` purescript 150 | exhaustMap :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject b 151 | ``` 152 | 153 | It's Like concatMap (a.k.a, `>>=`) EXCEPT that it ignores every new projected 154 | AsyncSubject if the previous projected AsyncSubject has not yet completed. 155 | 156 | #### `expand` 157 | 158 | ``` purescript 159 | expand :: forall a. AsyncSubject a -> (a -> AsyncSubject a) -> AsyncSubject a 160 | ``` 161 | 162 | It's similar to mergeMap, but applies the projection function to every source 163 | value as well as every output value. It's recursive. 164 | 165 | #### `groupBy` 166 | 167 | ``` purescript 168 | groupBy :: forall a b. (a -> b) -> AsyncSubject a -> AsyncSubject (AsyncSubject a) 169 | ``` 170 | 171 | Groups the items emitted by an AsyncSubject (arg2) according to the value 172 | returned by the grouping function (arg1). Each group becomes its own 173 | AsyncSubject. 174 | 175 | #### `mapTo` 176 | 177 | ``` purescript 178 | mapTo :: forall a b. b -> AsyncSubject a -> AsyncSubject b 179 | ``` 180 | 181 | Emits the given constant value on the output AsyncSubject every time 182 | the source AsyncSubject emits a value. 183 | 184 | #### `mergeMap` 185 | 186 | ``` purescript 187 | mergeMap :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject b 188 | ``` 189 | 190 | Maps each value to an AsyncSubject, then flattens all of these AsyncSubjects 191 | using mergeAll. It's just monadic `bind`. 192 | 193 | #### `mergeMapTo` 194 | 195 | ``` purescript 196 | mergeMapTo :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject b 197 | ``` 198 | 199 | Maps each value of the AsyncSubject (arg1) to the same inner AsyncSubject (arg2), 200 | then flattens the result. 201 | 202 | #### `pairwise` 203 | 204 | ``` purescript 205 | pairwise :: forall a. AsyncSubject a -> AsyncSubject (Array a) 206 | ``` 207 | 208 | Puts the current value and previous value together as an array, and emits that. 209 | 210 | #### `partition` 211 | 212 | ``` purescript 213 | partition :: forall a. (a -> Boolean) -> AsyncSubject a -> Array (AsyncSubject a) 214 | ``` 215 | 216 | Given a predicate function (arg1), and an AsyncSubject (arg2), it outputs a 217 | two element array of partitioned values 218 | (i.e., [ AsyncSubject valuesThatPassPredicate, AsyncSubject valuesThatFailPredicate ]). 219 | 220 | #### `scan` 221 | 222 | ``` purescript 223 | scan :: forall a b. (a -> b -> b) -> b -> AsyncSubject a -> AsyncSubject b 224 | ``` 225 | 226 | Given an accumulator function (arg1), an initial value (arg2), and 227 | a source AsyncSubject (arg3), it returns an AsyncSubject that emits the current 228 | accumlation whenever the source emits a value. 229 | 230 | #### `switchMap` 231 | 232 | ``` purescript 233 | switchMap :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject b 234 | ``` 235 | 236 | Projects each source value to an AsyncSubject which is merged in the output 237 | AsyncSubject, emitting values only from the most recently projected AsyncSubject. 238 | 239 | #### `switchMapTo` 240 | 241 | ``` purescript 242 | switchMapTo :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject b 243 | ``` 244 | 245 | It's like switchMap, but maps each value to the same inner AsyncSubject. 246 | 247 | #### `window` 248 | 249 | ``` purescript 250 | window :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject (AsyncSubject a) 251 | ``` 252 | 253 | It's like buffer, but emits a nested AsyncSubject instead of an array. 254 | 255 | #### `windowCount` 256 | 257 | ``` purescript 258 | windowCount :: forall a. Int -> Int -> AsyncSubject a -> AsyncSubject (AsyncSubject a) 259 | ``` 260 | 261 | It's like bufferCount, but emits a nested AsyncSubject instead of an array. 262 | 263 | #### `windowTime` 264 | 265 | ``` purescript 266 | windowTime :: forall a. Int -> Int -> AsyncSubject a -> AsyncSubject (AsyncSubject a) 267 | ``` 268 | 269 | It's like bufferTime, but emits a nested AsyncSubject instead of an array, 270 | and it doesn't take a maximum size parameter. arg1 is how long to 271 | buffer items into a new AsyncSubject, arg2 is the when the next buffer should begin, 272 | and arg3 is the source AsyncSubject. 273 | 274 | #### `windowToggle` 275 | 276 | ``` purescript 277 | windowToggle :: forall a b c. (AsyncSubject a) -> (AsyncSubject b) -> (b -> AsyncSubject c) -> (AsyncSubject (Array a)) 278 | ``` 279 | 280 | It's like bufferToggle, but emits a nested AsyncSubject instead of an array. 281 | 282 | #### `windowWhen` 283 | 284 | ``` purescript 285 | windowWhen :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject (AsyncSubject a) 286 | ``` 287 | 288 | It's like bufferWhen, but emits a nested AsyncSubject instead of an array. 289 | 290 | #### `audit` 291 | 292 | ``` purescript 293 | audit :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject a 294 | ``` 295 | 296 | It's like auditTime, but the silencing duration is determined by a second AsyncSubject. 297 | 298 | #### `auditTime` 299 | 300 | ``` purescript 301 | auditTime :: forall a. Int -> AsyncSubject a -> AsyncSubject a 302 | ``` 303 | 304 | Ignores source values for duration milliseconds, 305 | then emits the most recent value from the source AsyncSubject, then repeats this process. 306 | 307 | #### `debounce` 308 | 309 | ``` purescript 310 | debounce :: forall a. AsyncSubject a -> (a -> AsyncSubject Int) -> AsyncSubject a 311 | ``` 312 | 313 | It's like debounceTime, but the time span of emission silence is determined 314 | by a second AsyncSubject. Allows for a variable debounce rate. 315 | 316 | #### `debounceTime` 317 | 318 | ``` purescript 319 | debounceTime :: forall a. Int -> AsyncSubject a -> AsyncSubject a 320 | ``` 321 | 322 | It's like delay, but passes only the most recent value from each burst of emissions. 323 | 324 | #### `distinct` 325 | 326 | ``` purescript 327 | distinct :: forall a. AsyncSubject a -> AsyncSubject a 328 | ``` 329 | 330 | Returns an AsyncSubject that emits all items emitted by the source AsyncSubject 331 | that are distinct by comparison from previous items. 332 | 333 | #### `distinctUntilChanged` 334 | 335 | ``` purescript 336 | distinctUntilChanged :: forall a. AsyncSubject a -> AsyncSubject a 337 | ``` 338 | 339 | Returns an AsyncSubject that emits all items emitted by the source AsyncSubject 340 | that are distinct by comparison from the previous item. 341 | 342 | #### `elementAt` 343 | 344 | ``` purescript 345 | elementAt :: forall a. AsyncSubject a -> Int -> AsyncSubject a 346 | ``` 347 | 348 | Emits the single value at the specified index in a sequence of emissions 349 | from the source AsyncSubject. 350 | 351 | #### `filter` 352 | 353 | ``` purescript 354 | filter :: forall a. (a -> Boolean) -> AsyncSubject a -> AsyncSubject a 355 | ``` 356 | 357 | Filter items emitted by the source AsyncSubject by only emitting those that 358 | satisfy a specified predicate. 359 | 360 | #### `ignoreElements` 361 | 362 | ``` purescript 363 | ignoreElements :: forall a. AsyncSubject a -> AsyncSubject a 364 | ``` 365 | 366 | Ignores all items emitted by the source AsyncSubject and only passes calls of complete or error. 367 | 368 | #### `last` 369 | 370 | ``` purescript 371 | last :: forall a. AsyncSubject a -> AsyncSubject a 372 | ``` 373 | 374 | Returns an AsyncSubject that emits only the last item emitted by the source AsyncSubject. 375 | 376 | #### `sample` 377 | 378 | ``` purescript 379 | sample :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject a 380 | ``` 381 | 382 | It's like sampleTime, but samples whenever the notifier AsyncSubject emits something. 383 | 384 | #### `sampleTime` 385 | 386 | ``` purescript 387 | sampleTime :: forall a. Int -> AsyncSubject a -> AsyncSubject a 388 | ``` 389 | 390 | Periodically looks at the source AsyncSubject and emits whichever 391 | value it has most recently emitted since the previous sampling, unless the source has not emitted anything since the previous sampling. 392 | 393 | #### `skip` 394 | 395 | ``` purescript 396 | skip :: forall a. Int -> AsyncSubject a -> AsyncSubject a 397 | ``` 398 | 399 | Returns an AsyncSubject that skips n items emitted by an AsyncSubject. 400 | 401 | #### `skipUntil` 402 | 403 | ``` purescript 404 | skipUntil :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject a 405 | ``` 406 | 407 | Returns an AsyncSubject that skips items emitted by the source AsyncSubject until a second AsyncSubject emits an item. 408 | 409 | #### `skipWhile` 410 | 411 | ``` purescript 412 | skipWhile :: forall a. (a -> Boolean) -> AsyncSubject a -> AsyncSubject a 413 | ``` 414 | 415 | Returns an AsyncSubject that skips all items emitted 416 | by the source AsyncSubject as long as a specified condition holds true, 417 | but emits all further source items as soon as the condition becomes false. 418 | 419 | #### `take` 420 | 421 | ``` purescript 422 | take :: forall a. Int -> AsyncSubject a -> AsyncSubject a 423 | ``` 424 | 425 | Emits only the first n values emitted by the source AsyncSubject. 426 | 427 | #### `takeUntil` 428 | 429 | ``` purescript 430 | takeUntil :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject a 431 | ``` 432 | 433 | Lets values pass until a second AsyncSubject emits something. Then, it completes. 434 | 435 | #### `takeWhile` 436 | 437 | ``` purescript 438 | takeWhile :: forall a. (a -> Boolean) -> AsyncSubject a -> AsyncSubject a 439 | ``` 440 | 441 | Emits values emitted by the source AsyncSubject so long as each value satisfies 442 | the given predicate, and then completes as soon as this predicate is not satisfied. 443 | 444 | #### `throttle` 445 | 446 | ``` purescript 447 | throttle :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject a 448 | ``` 449 | 450 | It's like throttleTime, but the silencing duration is determined by a second AsyncSubject. 451 | 452 | #### `throttleTime` 453 | 454 | ``` purescript 455 | throttleTime :: forall a. Int -> AsyncSubject a -> AsyncSubject a 456 | ``` 457 | 458 | Emits a value from the source AsyncSubject, then ignores subsequent source values 459 | for duration milliseconds, then repeats this process. 460 | 461 | #### `combineLatest` 462 | 463 | ``` purescript 464 | combineLatest :: forall a b c. (a -> b -> c) -> AsyncSubject a -> AsyncSubject b -> AsyncSubject c 465 | ``` 466 | 467 | An AsyncSubject of projected values from the most recent values from each input AsyncSubject. 468 | 469 | #### `concat` 470 | 471 | ``` purescript 472 | concat :: forall a. AsyncSubject a -> AsyncSubject a -> AsyncSubject a 473 | ``` 474 | 475 | Concatenates two AsyncSubjects together by sequentially emitting their values, one AsyncSubject after the other. 476 | 477 | #### `concatAll` 478 | 479 | ``` purescript 480 | concatAll :: forall a. AsyncSubject (AsyncSubject a) -> AsyncSubject a 481 | ``` 482 | 483 | Converts a higher-order AsyncSubject into a first-order AsyncSubject by concatenating the inner AsyncSubjects in order. 484 | 485 | #### `exhaust` 486 | 487 | ``` purescript 488 | exhaust :: forall a. AsyncSubject (AsyncSubject a) -> AsyncSubject a 489 | ``` 490 | 491 | Flattens an AsyncSubject-of-AsyncSubjects by dropping the next inner AsyncSubjects 492 | while the current inner is still executing. 493 | 494 | #### `merge` 495 | 496 | ``` purescript 497 | merge :: forall a. AsyncSubject a -> AsyncSubject a -> AsyncSubject a 498 | ``` 499 | 500 | Creates an output AsyncSubject which concurrently emits all values from each input AsyncSubject. 501 | 502 | #### `mergeAll` 503 | 504 | ``` purescript 505 | mergeAll :: forall a. AsyncSubject (AsyncSubject a) -> AsyncSubject a 506 | ``` 507 | 508 | Converts a higher-order AsyncSubject into a first-order AsyncSubject 509 | which concurrently delivers all values that are emitted on the inner AsyncSubjects. 510 | 511 | #### `race` 512 | 513 | ``` purescript 514 | race :: forall a. Array (AsyncSubject a) -> AsyncSubject a 515 | ``` 516 | 517 | Returns an AsyncSubject that mirrors the first source AsyncSubject to emit an 518 | item from the array of AsyncSubjects. 519 | 520 | #### `startWith` 521 | 522 | ``` purescript 523 | startWith :: forall a. Array a -> AsyncSubject a -> AsyncSubject a 524 | ``` 525 | 526 | Returns an AsyncSubject that emits the items in the given Array before 527 | it begins to emit items emitted by the source AsyncSubject. 528 | 529 | #### `withLatestFrom` 530 | 531 | ``` purescript 532 | withLatestFrom :: forall a b c. (a -> b -> c) -> AsyncSubject a -> AsyncSubject b -> AsyncSubject c 533 | ``` 534 | 535 | Combines each value from the source AsyncSubjects using a project function to 536 | determine the value to be emitted on the output AsyncSubject. 537 | 538 | #### `zip` 539 | 540 | ``` purescript 541 | zip :: forall a. Array (AsyncSubject a) -> AsyncSubject (Array a) 542 | ``` 543 | 544 | Waits for each AsyncSubject to emit a value. Once this occurs, all values 545 | with the corresponding index will be emitted. This will continue until at 546 | least one inner AsyncSubject completes. 547 | 548 | #### `catch` 549 | 550 | ``` purescript 551 | catch :: forall a. (AsyncSubject a) -> (Error -> AsyncSubject a) -> (AsyncSubject a) 552 | ``` 553 | 554 | #### `retry` 555 | 556 | ``` purescript 557 | retry :: forall a. Int -> AsyncSubject a -> AsyncSubject a 558 | ``` 559 | 560 | If the source AsyncSubject calls error, this method will resubscribe to the 561 | source AsyncSubject n times rather than propagating the error call. 562 | 563 | #### `delay` 564 | 565 | ``` purescript 566 | delay :: forall a. Int -> AsyncSubject a -> AsyncSubject a 567 | ``` 568 | 569 | Time shifts each item by some specified amount of milliseconds. 570 | 571 | #### `delayWhen` 572 | 573 | ``` purescript 574 | delayWhen :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject a 575 | ``` 576 | 577 | Delays the emission of items from the source AsyncSubject by a given time 578 | span determined by the emissions of another AsyncSubject. 579 | 580 | #### `dematerialize` 581 | 582 | ``` purescript 583 | dematerialize :: forall a. AsyncSubject (Notification a) -> AsyncSubject a 584 | ``` 585 | 586 | #### `materialize` 587 | 588 | ``` purescript 589 | materialize :: forall a. AsyncSubject a -> AsyncSubject (Notification a) 590 | ``` 591 | 592 | #### `performEach` 593 | 594 | ``` purescript 595 | performEach :: forall a e. AsyncSubject a -> (a -> Eff e Unit) -> Eff e (AsyncSubject a) 596 | ``` 597 | 598 | Performs the effect on each value of the AsyncSubject. An alias for `do`. 599 | Useful for testing (transparently performing an effect outside of a subscription). 600 | 601 | #### `toArray` 602 | 603 | ``` purescript 604 | toArray :: forall a. AsyncSubject a -> AsyncSubject (Array a) 605 | ``` 606 | 607 | #### `count` 608 | 609 | ``` purescript 610 | count :: forall a. AsyncSubject a -> AsyncSubject Int 611 | ``` 612 | 613 | Counts the number of emissions on the source and emits that number when the source completes. 614 | 615 | 616 | -------------------------------------------------------------------------------- /generated-docs/RxJS/BehaviorSubject.md: -------------------------------------------------------------------------------- 1 | ## Module RxJS.BehaviorSubject 2 | 3 | #### `BehaviorSubject` 4 | 5 | ``` purescript 6 | data BehaviorSubject :: Type -> Type 7 | ``` 8 | 9 | Please see [RxJS Version 5.* documentation](http://reactivex.io/rxjs/) for 10 | additional details on proper usage of the library. 11 | 12 | ##### Instances 13 | ``` purescript 14 | Functor BehaviorSubject 15 | Apply BehaviorSubject 16 | Applicative BehaviorSubject 17 | Bind BehaviorSubject 18 | Monad BehaviorSubject 19 | Semigroup (BehaviorSubject a) 20 | Alt BehaviorSubject 21 | ``` 22 | 23 | #### `observeOn` 24 | 25 | ``` purescript 26 | observeOn :: forall a. Scheduler -> BehaviorSubject a -> BehaviorSubject a 27 | ``` 28 | 29 | Makes every `next` call run in the new Scheduler. 30 | 31 | #### `subscribeOn` 32 | 33 | ``` purescript 34 | subscribeOn :: forall a. Scheduler -> BehaviorSubject a -> BehaviorSubject a 35 | ``` 36 | 37 | Makes subscription happen on a given Scheduler. 38 | 39 | #### `subscribe` 40 | 41 | ``` purescript 42 | subscribe :: forall a e. Subscriber a -> BehaviorSubject a -> Eff e Subscription 43 | ``` 44 | 45 | Subscribing to an BehaviorSubject is like calling a function, providing 46 | `next`, `error` and `completed` effects to which the data will be delivered. 47 | 48 | #### `subscribeNext` 49 | 50 | ``` purescript 51 | subscribeNext :: forall a e. (a -> Eff e Unit) -> BehaviorSubject a -> Eff e Subscription 52 | ``` 53 | 54 | #### `just` 55 | 56 | ``` purescript 57 | just :: forall a. a -> BehaviorSubject a 58 | ``` 59 | 60 | Creates an BehaviorSubject that emits the value specify, 61 | and then emits a complete notification. An alias for `of`. 62 | 63 | #### `next` 64 | 65 | ``` purescript 66 | next :: forall a e. a -> BehaviorSubject a -> Eff e Unit 67 | ``` 68 | 69 | Send a new value to a BehaviorSubject 70 | 71 | #### `send` 72 | 73 | ``` purescript 74 | send :: forall a e. a -> BehaviorSubject a -> Eff e Unit 75 | ``` 76 | 77 | An alias for next 78 | 79 | #### `asObservable` 80 | 81 | ``` purescript 82 | asObservable :: forall a. BehaviorSubject a -> Observable a 83 | ``` 84 | 85 | Create an Observable from a BehaviorSubject 86 | 87 | #### `getValue` 88 | 89 | ``` purescript 90 | getValue :: forall a e. BehaviorSubject a -> Eff e a 91 | ``` 92 | 93 | Obtain the current value of a BehaviorSubject 94 | 95 | #### `buffer` 96 | 97 | ``` purescript 98 | buffer :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject (Array a) 99 | ``` 100 | 101 | Collects values from the first BehaviorSubject into an Array, and emits that array only when 102 | second BehaviorSubject emits. 103 | 104 | #### `bufferCount` 105 | 106 | ``` purescript 107 | bufferCount :: forall a. Int -> Int -> BehaviorSubject a -> BehaviorSubject (Array a) 108 | ``` 109 | 110 | Collects values from the past as an array, emits that array when 111 | its size (arg1) reaches the specified buffer size, and starts a new buffer. 112 | The new buffer starts with nth (arg2) element of the BehaviorSubject counting 113 | from the beginning of the *last* buffer. 114 | 115 | #### `bufferToggle` 116 | 117 | ``` purescript 118 | bufferToggle :: forall a b c. (BehaviorSubject a) -> (BehaviorSubject b) -> (b -> BehaviorSubject c) -> (BehaviorSubject (Array a)) 119 | ``` 120 | 121 | Collects values from the source BehaviorSubject (arg1) as an array. Starts collecting only when 122 | the opening (arg2) BehaviorSubject emits, and calls the closingSelector function (arg3) to get an BehaviorSubject 123 | that decides when to close the buffer. Another buffer opens when the 124 | opening BehaviorSubject emits its next value. 125 | 126 | #### `bufferWhen` 127 | 128 | ``` purescript 129 | bufferWhen :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject (Array a) 130 | ``` 131 | 132 | Collects values from the past as an array. When it starts collecting values, 133 | it calls a function that returns an BehaviorSubject that emits to close the 134 | buffer and restart collecting. 135 | 136 | #### `concatMap` 137 | 138 | ``` purescript 139 | concatMap :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject b 140 | ``` 141 | 142 | Equivalent to mergeMap (a.k.a, `>>=`) EXCEPT that, unlike mergeMap, 143 | the next bind will not run until the BehaviorSubject generated by the projection function (arg2) 144 | completes. That is, composition is sequential, not concurrent. 145 | Warning: if source values arrive endlessly and faster than their corresponding 146 | inner BehaviorSubjects can complete, it will result in memory issues as inner 147 | BehaviorSubjects amass in an unbounded buffer waiting for their turn to be subscribed to. 148 | 149 | #### `concatMapTo` 150 | 151 | ``` purescript 152 | concatMapTo :: forall a b c. BehaviorSubject a -> BehaviorSubject b -> (a -> b -> BehaviorSubject c) -> BehaviorSubject c 153 | ``` 154 | 155 | The type signature explains it best. Warning: Like `concatMap`, composition is sequential. 156 | 157 | #### `exhaustMap` 158 | 159 | ``` purescript 160 | exhaustMap :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject b 161 | ``` 162 | 163 | It's Like concatMap (a.k.a, `>>=`) EXCEPT that it ignores every new projected 164 | BehaviorSubject if the previous projected BehaviorSubject has not yet completed. 165 | 166 | #### `expand` 167 | 168 | ``` purescript 169 | expand :: forall a. BehaviorSubject a -> (a -> BehaviorSubject a) -> BehaviorSubject a 170 | ``` 171 | 172 | It's similar to mergeMap, but applies the projection function to every source 173 | value as well as every output value. It's recursive. 174 | 175 | #### `groupBy` 176 | 177 | ``` purescript 178 | groupBy :: forall a b. (a -> b) -> BehaviorSubject a -> BehaviorSubject (BehaviorSubject a) 179 | ``` 180 | 181 | Groups the items emitted by an BehaviorSubject (arg2) according to the value 182 | returned by the grouping function (arg1). Each group becomes its own 183 | BehaviorSubject. 184 | 185 | #### `mapTo` 186 | 187 | ``` purescript 188 | mapTo :: forall a b. b -> BehaviorSubject a -> BehaviorSubject b 189 | ``` 190 | 191 | Emits the given constant value on the output BehaviorSubject every time 192 | the source BehaviorSubject emits a value. 193 | 194 | #### `mergeMap` 195 | 196 | ``` purescript 197 | mergeMap :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject b 198 | ``` 199 | 200 | Maps each value to an BehaviorSubject, then flattens all of these BehaviorSubjects 201 | using mergeAll. It's just monadic `bind`. 202 | 203 | #### `mergeMapTo` 204 | 205 | ``` purescript 206 | mergeMapTo :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject b 207 | ``` 208 | 209 | Maps each value of the BehaviorSubject (arg1) to the same inner BehaviorSubject (arg2), 210 | then flattens the result. 211 | 212 | #### `pairwise` 213 | 214 | ``` purescript 215 | pairwise :: forall a. BehaviorSubject a -> BehaviorSubject (Array a) 216 | ``` 217 | 218 | Puts the current value and previous value together as an array, and emits that. 219 | 220 | #### `partition` 221 | 222 | ``` purescript 223 | partition :: forall a. (a -> Boolean) -> BehaviorSubject a -> Array (BehaviorSubject a) 224 | ``` 225 | 226 | Given a predicate function (arg1), and an BehaviorSubject (arg2), it outputs a 227 | two element array of partitioned values 228 | (i.e., [ BehaviorSubject valuesThatPassPredicate, BehaviorSubject valuesThatFailPredicate ]). 229 | 230 | #### `scan` 231 | 232 | ``` purescript 233 | scan :: forall a b. (a -> b -> b) -> b -> BehaviorSubject a -> BehaviorSubject b 234 | ``` 235 | 236 | Given an accumulator function (arg1), an initial value (arg2), and 237 | a source BehaviorSubject (arg3), it returns an BehaviorSubject that emits the current 238 | accumlation whenever the source emits a value. 239 | 240 | #### `switchMap` 241 | 242 | ``` purescript 243 | switchMap :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject b 244 | ``` 245 | 246 | Projects each source value to an BehaviorSubject which is merged in the output 247 | BehaviorSubject, emitting values only from the most recently projected BehaviorSubject. 248 | 249 | #### `switchMapTo` 250 | 251 | ``` purescript 252 | switchMapTo :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject b 253 | ``` 254 | 255 | It's like switchMap, but maps each value to the same inner BehaviorSubject. 256 | 257 | #### `window` 258 | 259 | ``` purescript 260 | window :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject (BehaviorSubject a) 261 | ``` 262 | 263 | It's like buffer, but emits a nested BehaviorSubject instead of an array. 264 | 265 | #### `windowCount` 266 | 267 | ``` purescript 268 | windowCount :: forall a. Int -> Int -> BehaviorSubject a -> BehaviorSubject (BehaviorSubject a) 269 | ``` 270 | 271 | It's like bufferCount, but emits a nested BehaviorSubject instead of an array. 272 | 273 | #### `windowTime` 274 | 275 | ``` purescript 276 | windowTime :: forall a. Int -> Int -> BehaviorSubject a -> BehaviorSubject (BehaviorSubject a) 277 | ``` 278 | 279 | It's like bufferTime, but emits a nested BehaviorSubject instead of an array, 280 | and it doesn't take a maximum size parameter. arg1 is how long to 281 | buffer items into a new BehaviorSubject, arg2 is the when the next buffer should begin, 282 | and arg3 is the source BehaviorSubject. 283 | 284 | #### `windowToggle` 285 | 286 | ``` purescript 287 | windowToggle :: forall a b c. (BehaviorSubject a) -> (BehaviorSubject b) -> (b -> BehaviorSubject c) -> (BehaviorSubject (Array a)) 288 | ``` 289 | 290 | It's like bufferToggle, but emits a nested BehaviorSubject instead of an array. 291 | 292 | #### `windowWhen` 293 | 294 | ``` purescript 295 | windowWhen :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject (BehaviorSubject a) 296 | ``` 297 | 298 | It's like bufferWhen, but emits a nested BehaviorSubject instead of an array. 299 | 300 | #### `audit` 301 | 302 | ``` purescript 303 | audit :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject a 304 | ``` 305 | 306 | It's like auditTime, but the silencing duration is determined by a second BehaviorSubject. 307 | 308 | #### `auditTime` 309 | 310 | ``` purescript 311 | auditTime :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 312 | ``` 313 | 314 | Ignores source values for duration milliseconds, 315 | then emits the most recent value from the source BehaviorSubject, then repeats this process. 316 | 317 | #### `debounce` 318 | 319 | ``` purescript 320 | debounce :: forall a. BehaviorSubject a -> (a -> BehaviorSubject Int) -> BehaviorSubject a 321 | ``` 322 | 323 | It's like debounceTime, but the time span of emission silence is determined 324 | by a second BehaviorSubject. Allows for a variable debounce rate. 325 | 326 | #### `debounceTime` 327 | 328 | ``` purescript 329 | debounceTime :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 330 | ``` 331 | 332 | It's like delay, but passes only the most recent value from each burst of emissions. 333 | 334 | #### `distinct` 335 | 336 | ``` purescript 337 | distinct :: forall a. BehaviorSubject a -> BehaviorSubject a 338 | ``` 339 | 340 | Returns an BehaviorSubject that emits all items emitted by the source BehaviorSubject 341 | that are distinct by comparison from previous items. 342 | 343 | #### `distinctUntilChanged` 344 | 345 | ``` purescript 346 | distinctUntilChanged :: forall a. BehaviorSubject a -> BehaviorSubject a 347 | ``` 348 | 349 | Returns an BehaviorSubject that emits all items emitted by the source BehaviorSubject 350 | that are distinct by comparison from the previous item. 351 | 352 | #### `elementAt` 353 | 354 | ``` purescript 355 | elementAt :: forall a. BehaviorSubject a -> Int -> BehaviorSubject a 356 | ``` 357 | 358 | Emits the single value at the specified index in a sequence of emissions 359 | from the source BehaviorSubject. 360 | 361 | #### `filter` 362 | 363 | ``` purescript 364 | filter :: forall a. (a -> Boolean) -> BehaviorSubject a -> BehaviorSubject a 365 | ``` 366 | 367 | Filter items emitted by the source BehaviorSubject by only emitting those that 368 | satisfy a specified predicate. 369 | 370 | #### `ignoreElements` 371 | 372 | ``` purescript 373 | ignoreElements :: forall a. BehaviorSubject a -> BehaviorSubject a 374 | ``` 375 | 376 | Ignores all items emitted by the source BehaviorSubject and only passes calls of complete or error. 377 | 378 | #### `last` 379 | 380 | ``` purescript 381 | last :: forall a. BehaviorSubject a -> BehaviorSubject a 382 | ``` 383 | 384 | Returns an BehaviorSubject that emits only the last item emitted by the source BehaviorSubject. 385 | 386 | #### `sample` 387 | 388 | ``` purescript 389 | sample :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject a 390 | ``` 391 | 392 | It's like sampleTime, but samples whenever the notifier BehaviorSubject emits something. 393 | 394 | #### `sampleTime` 395 | 396 | ``` purescript 397 | sampleTime :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 398 | ``` 399 | 400 | Periodically looks at the source BehaviorSubject and emits whichever 401 | value it has most recently emitted since the previous sampling, unless the source has not emitted anything since the previous sampling. 402 | 403 | #### `skip` 404 | 405 | ``` purescript 406 | skip :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 407 | ``` 408 | 409 | Returns an BehaviorSubject that skips n items emitted by an BehaviorSubject. 410 | 411 | #### `skipUntil` 412 | 413 | ``` purescript 414 | skipUntil :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject a 415 | ``` 416 | 417 | Returns an BehaviorSubject that skips items emitted by the source BehaviorSubject until a second BehaviorSubject emits an item. 418 | 419 | #### `skipWhile` 420 | 421 | ``` purescript 422 | skipWhile :: forall a. (a -> Boolean) -> BehaviorSubject a -> BehaviorSubject a 423 | ``` 424 | 425 | Returns an BehaviorSubject that skips all items emitted 426 | by the source BehaviorSubject as long as a specified condition holds true, 427 | but emits all further source items as soon as the condition becomes false. 428 | 429 | #### `take` 430 | 431 | ``` purescript 432 | take :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 433 | ``` 434 | 435 | Emits only the first n values emitted by the source BehaviorSubject. 436 | 437 | #### `takeUntil` 438 | 439 | ``` purescript 440 | takeUntil :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject a 441 | ``` 442 | 443 | Lets values pass until a second BehaviorSubject emits something. Then, it completes. 444 | 445 | #### `takeWhile` 446 | 447 | ``` purescript 448 | takeWhile :: forall a. (a -> Boolean) -> BehaviorSubject a -> BehaviorSubject a 449 | ``` 450 | 451 | Emits values emitted by the source BehaviorSubject so long as each value satisfies 452 | the given predicate, and then completes as soon as this predicate is not satisfied. 453 | 454 | #### `throttle` 455 | 456 | ``` purescript 457 | throttle :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject a 458 | ``` 459 | 460 | It's like throttleTime, but the silencing duration is determined by a second BehaviorSubject. 461 | 462 | #### `throttleTime` 463 | 464 | ``` purescript 465 | throttleTime :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 466 | ``` 467 | 468 | Emits a value from the source BehaviorSubject, then ignores subsequent source values 469 | for duration milliseconds, then repeats this process. 470 | 471 | #### `combineLatest` 472 | 473 | ``` purescript 474 | combineLatest :: forall a b c. (a -> b -> c) -> BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject c 475 | ``` 476 | 477 | An BehaviorSubject of projected values from the most recent values from each input BehaviorSubject. 478 | 479 | #### `concat` 480 | 481 | ``` purescript 482 | concat :: forall a. BehaviorSubject a -> BehaviorSubject a -> BehaviorSubject a 483 | ``` 484 | 485 | Concatenates two BehaviorSubjects together by sequentially emitting their values, one BehaviorSubject after the other. 486 | 487 | #### `concatAll` 488 | 489 | ``` purescript 490 | concatAll :: forall a. BehaviorSubject (BehaviorSubject a) -> BehaviorSubject a 491 | ``` 492 | 493 | Converts a higher-order BehaviorSubject into a first-order BehaviorSubject by concatenating the inner BehaviorSubjects in order. 494 | 495 | #### `exhaust` 496 | 497 | ``` purescript 498 | exhaust :: forall a. BehaviorSubject (BehaviorSubject a) -> BehaviorSubject a 499 | ``` 500 | 501 | Flattens an BehaviorSubject-of-BehaviorSubjects by dropping the next inner BehaviorSubjects 502 | while the current inner is still executing. 503 | 504 | #### `merge` 505 | 506 | ``` purescript 507 | merge :: forall a. BehaviorSubject a -> BehaviorSubject a -> BehaviorSubject a 508 | ``` 509 | 510 | Creates an output BehaviorSubject which concurrently emits all values from each input BehaviorSubject. 511 | 512 | #### `mergeAll` 513 | 514 | ``` purescript 515 | mergeAll :: forall a. BehaviorSubject (BehaviorSubject a) -> BehaviorSubject a 516 | ``` 517 | 518 | Converts a higher-order BehaviorSubject into a first-order BehaviorSubject 519 | which concurrently delivers all values that are emitted on the inner BehaviorSubjects. 520 | 521 | #### `race` 522 | 523 | ``` purescript 524 | race :: forall a. Array (BehaviorSubject a) -> BehaviorSubject a 525 | ``` 526 | 527 | Returns an BehaviorSubject that mirrors the first source BehaviorSubject to emit an 528 | item from the array of BehaviorSubjects. 529 | 530 | #### `startWith` 531 | 532 | ``` purescript 533 | startWith :: forall a. Array a -> BehaviorSubject a -> BehaviorSubject a 534 | ``` 535 | 536 | Returns an BehaviorSubject that emits the items in the given Array before 537 | it begins to emit items emitted by the source BehaviorSubject. 538 | 539 | #### `withLatestFrom` 540 | 541 | ``` purescript 542 | withLatestFrom :: forall a b c. (a -> b -> c) -> BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject c 543 | ``` 544 | 545 | Combines each value from the source BehaviorSubjects using a project function to 546 | determine the value to be emitted on the output BehaviorSubject. 547 | 548 | #### `zip` 549 | 550 | ``` purescript 551 | zip :: forall a. Array (BehaviorSubject a) -> BehaviorSubject (Array a) 552 | ``` 553 | 554 | Waits for each BehaviorSubject to emit a value. Once this occurs, all values 555 | with the corresponding index will be emitted. This will continue until at 556 | least one inner BehaviorSubject completes. 557 | 558 | #### `catch` 559 | 560 | ``` purescript 561 | catch :: forall a. (BehaviorSubject a) -> (Error -> BehaviorSubject a) -> (BehaviorSubject a) 562 | ``` 563 | 564 | #### `retry` 565 | 566 | ``` purescript 567 | retry :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 568 | ``` 569 | 570 | If the source BehaviorSubject calls error, this method will resubscribe to the 571 | source BehaviorSubject n times rather than propagating the error call. 572 | 573 | #### `delay` 574 | 575 | ``` purescript 576 | delay :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 577 | ``` 578 | 579 | Time shifts each item by some specified amount of milliseconds. 580 | 581 | #### `delayWhen` 582 | 583 | ``` purescript 584 | delayWhen :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject a 585 | ``` 586 | 587 | Delays the emission of items from the source BehaviorSubject by a given time 588 | span determined by the emissions of another BehaviorSubject. 589 | 590 | #### `dematerialize` 591 | 592 | ``` purescript 593 | dematerialize :: forall a. BehaviorSubject (Notification a) -> BehaviorSubject a 594 | ``` 595 | 596 | #### `materialize` 597 | 598 | ``` purescript 599 | materialize :: forall a. BehaviorSubject a -> BehaviorSubject (Notification a) 600 | ``` 601 | 602 | #### `performEach` 603 | 604 | ``` purescript 605 | performEach :: forall a e. BehaviorSubject a -> (a -> Eff e Unit) -> Eff e (BehaviorSubject a) 606 | ``` 607 | 608 | Performs the effect on each value of the BehaviorSubject. An alias for `do`. 609 | Useful for testing (transparently performing an effect outside of a subscription). 610 | 611 | #### `toArray` 612 | 613 | ``` purescript 614 | toArray :: forall a. BehaviorSubject a -> BehaviorSubject (Array a) 615 | ``` 616 | 617 | #### `count` 618 | 619 | ``` purescript 620 | count :: forall a. BehaviorSubject a -> BehaviorSubject Int 621 | ``` 622 | 623 | Counts the number of emissions on the source and emits that number when the source completes. 624 | 625 | 626 | -------------------------------------------------------------------------------- /generated-docs/RxJS/Notification.md: -------------------------------------------------------------------------------- 1 | ## Module RxJS.Notification 2 | 3 | #### `Notification` 4 | 5 | ``` purescript 6 | data Notification a 7 | = OnError Error 8 | | OnNext a 9 | | OnComplete 10 | ``` 11 | 12 | ##### Instances 13 | ``` purescript 14 | (Show a) => Show (Notification a) 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /generated-docs/RxJS/Observable.md: -------------------------------------------------------------------------------- 1 | ## Module RxJS.Observable 2 | 3 | #### `Observable` 4 | 5 | ``` purescript 6 | data Observable :: Type -> Type 7 | ``` 8 | 9 | *Note*: A couple operators are not wrapped (namely, `bindCallback`, `bindNodeCallback`) because RxJS 10 | implementation details prevent giving the operators an "honest" PureScript type. 11 | However, such operators are replaced easily using `Aff` with the `AsyncSubject` module. 12 | Please see [RxJS Version 5.* documentation](http://reactivex.io/rxjs/) for 13 | additional details on proper usage of the library. 14 | 15 | ##### Instances 16 | ``` purescript 17 | Monoid (Observable a) 18 | Functor Observable 19 | Apply Observable 20 | Applicative Observable 21 | Bind Observable 22 | Monad Observable 23 | Semigroup (Observable a) 24 | Alt Observable 25 | Plus Observable 26 | Alternative Observable 27 | MonadZero Observable 28 | MonadPlus Observable 29 | MonadError Error Observable 30 | MonadThrow Error Observable 31 | ``` 32 | 33 | #### `observeOn` 34 | 35 | ``` purescript 36 | observeOn :: forall a. Scheduler -> Observable a -> Observable a 37 | ``` 38 | 39 | Makes every `next` call run in the new Scheduler. 40 | 41 | #### `subscribeOn` 42 | 43 | ``` purescript 44 | subscribeOn :: forall a. Scheduler -> Observable a -> Observable a 45 | ``` 46 | 47 | Makes subscription happen on a given Scheduler. 48 | 49 | #### `subscribe` 50 | 51 | ``` purescript 52 | subscribe :: forall a e. Subscriber a -> Observable a -> Eff e Subscription 53 | ``` 54 | 55 | Subscribing to an Observable is like calling a function, providing 56 | `next`, `error` and `completed` effects to which the data will be delivered. 57 | 58 | #### `subscribeNext` 59 | 60 | ``` purescript 61 | subscribeNext :: forall a e. (a -> Eff e Unit) -> Observable a -> Eff e Subscription 62 | ``` 63 | 64 | #### `fromArray` 65 | 66 | ``` purescript 67 | fromArray :: forall a. Array a -> Observable a 68 | ``` 69 | 70 | Creates an Observable from an Array. 71 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/from.png) 72 | 73 | #### `fromEvent` 74 | 75 | ``` purescript 76 | fromEvent :: forall e. EventTarget -> EventType -> Eff e (Observable Event) 77 | ``` 78 | 79 | Creates an Observable that emits events of the specified type coming from the given event target. 80 | 81 | #### `interval` 82 | 83 | ``` purescript 84 | interval :: Int -> Observable Int 85 | ``` 86 | 87 | Returns an Observable that emits an infinite sequence of ascending 88 | integers, with a constant interval of time of your choosing between those 89 | emissions. 90 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/interval.png) 91 | 92 | #### `just` 93 | 94 | ``` purescript 95 | just :: forall a. a -> Observable a 96 | ``` 97 | 98 | Creates an Observable that emits the value specify, 99 | and then emits a complete notification. An alias for `of`. 100 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/from.png) 101 | 102 | #### `every` 103 | 104 | ``` purescript 105 | every :: forall a. Observable a -> (a -> Boolean) -> Observable Boolean 106 | ``` 107 | 108 | Determines whether all elements of an observable sequence satisfy a condition. 109 | Returns an observable sequence containing a single element determining whether all 110 | elements in the source sequence pass the test in the specified predicate. 111 | 112 | #### `never` 113 | 114 | ``` purescript 115 | never :: forall a. Observable a 116 | ``` 117 | 118 | Creates an Observable that emits no items. Subscriptions it must be 119 | disposed manually. 120 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/never.png) 121 | 122 | #### `range` 123 | 124 | ``` purescript 125 | range :: Int -> Int -> Observable Int 126 | ``` 127 | 128 | The range operator emits a range of sequential integers, in order, where 129 | you select the start of the range and its length 130 | ![marble diagram](http://reactivex.io/rxjs/img/range.png" width="640" height="195"> 131 | 132 | #### `throw` 133 | 134 | ``` purescript 135 | throw :: forall a. Error -> Observable a 136 | ``` 137 | 138 | Creates an Observable that immediately sends an error notification. 139 | 140 | #### `timer` 141 | 142 | ``` purescript 143 | timer :: Int -> Int -> Observable Int 144 | ``` 145 | 146 | Creates an Observable that, upon subscription, emits and infinite sequence of ascending integers, 147 | after a specified delay, every specified period. Delay and period are in 148 | milliseconds. 149 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/timer.png) 150 | 151 | #### `buffer` 152 | 153 | ``` purescript 154 | buffer :: forall a b. Observable a -> Observable b -> Observable (Array a) 155 | ``` 156 | 157 | Collects values from the first Observable into an Array, and emits that array only when 158 | second Observable emits. 159 | ![marble diagram](http://reactivex.io/documentation/operators/images/buffer1.png) 160 | 161 | #### `bufferCount` 162 | 163 | ``` purescript 164 | bufferCount :: forall a. Int -> Int -> Observable a -> Observable (Array a) 165 | ``` 166 | 167 | Collects values from the past as an array, emits that array when 168 | its size (arg1) reaches the specified buffer size, and starts a new buffer. 169 | The new buffer starts with nth (arg2) element of the Observable counting 170 | from the beginning of the *last* buffer. 171 | ![marble diagram](http://reactivex.io/documentation/operators/images/buffer1.png) 172 | 173 | #### `bufferToggle` 174 | 175 | ``` purescript 176 | bufferToggle :: forall a b c. (Observable a) -> (Observable b) -> (b -> Observable c) -> (Observable (Array a)) 177 | ``` 178 | 179 | Collects values from the source Observable (arg1) as an array. Starts collecting only when 180 | the opening (arg2) Observable emits, and calls the closingSelector function (arg3) to get an Observable 181 | that decides when to close the buffer. Another buffer opens when the 182 | opening Observable emits its next value. 183 | ![marble diagram](http://reactivex.io/documentation/operators/images/buffer2.png) 184 | 185 | #### `bufferWhen` 186 | 187 | ``` purescript 188 | bufferWhen :: forall a b. Observable a -> (a -> Observable b) -> Observable (Array a) 189 | ``` 190 | 191 | Collects values from the past as an array. When it starts collecting values, 192 | it calls a function that returns an Observable that emits to close the 193 | buffer and restart collecting. 194 | ![marble diagram](http://reactivex.io/documentation/operators/images/buffer1.png) 195 | 196 | #### `concatMap` 197 | 198 | ``` purescript 199 | concatMap :: forall a b. Observable a -> (a -> Observable b) -> Observable b 200 | ``` 201 | 202 | Equivalent to mergeMap (a.k.a, `>>=`) EXCEPT that, unlike mergeMap, 203 | the next bind will not run until the Observable generated by the projection function (arg2) 204 | completes. That is, composition is sequential, not concurrent. 205 | Warning: if source values arrive endlessly and faster than their corresponding 206 | inner Observables can complete, it will result in memory issues as inner 207 | Observables amass in an unbounded buffer waiting for their turn to be subscribed to. 208 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/concatMap.png) 209 | 210 | #### `concatMapTo` 211 | 212 | ``` purescript 213 | concatMapTo :: forall a b c. Observable a -> Observable b -> (a -> b -> Observable c) -> Observable c 214 | ``` 215 | 216 | The type signature explains it best. Warning: Like `concatMap`, composition is sequential. 217 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/concatMap.png) 218 | 219 | #### `exhaustMap` 220 | 221 | ``` purescript 222 | exhaustMap :: forall a b. Observable a -> (a -> Observable b) -> Observable b 223 | ``` 224 | 225 | It's Like concatMap (a.k.a, `>>=`) EXCEPT that it ignores every new projected 226 | Observable if the previous projected Observable has not yet completed. 227 | ![marble diagram](http://reactivex.io/rxjs/img/exhaustMap.png) 228 | 229 | #### `expand` 230 | 231 | ``` purescript 232 | expand :: forall a. Observable a -> (a -> Observable a) -> Observable a 233 | ``` 234 | 235 | It's similar to mergeMap, but applies the projection function to every source 236 | value as well as every output value. It's recursive. 237 | 238 | #### `groupBy` 239 | 240 | ``` purescript 241 | groupBy :: forall a b. (a -> b) -> Observable a -> Observable (Observable a) 242 | ``` 243 | 244 | Groups the items emitted by an Observable (arg2) according to the value 245 | returned by the grouping function (arg1). Each group becomes its own 246 | Observable. 247 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/groupBy.png) 248 | 249 | #### `mapTo` 250 | 251 | ``` purescript 252 | mapTo :: forall a b. b -> Observable a -> Observable b 253 | ``` 254 | 255 | Emits the given constant value on the output Observable every time 256 | the source Observable emits a value. 257 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/map.png) 258 | 259 | #### `mergeMap` 260 | 261 | ``` purescript 262 | mergeMap :: forall a b. Observable a -> (a -> Observable b) -> Observable b 263 | ``` 264 | 265 | Maps each value to an Observable, then flattens all of these Observables 266 | using mergeAll. It's just monadic `bind`. 267 | ![marble diagram](http://reactivex.io/documentation/operators/images/flatMap.c.png) 268 | 269 | #### `mergeMapTo` 270 | 271 | ``` purescript 272 | mergeMapTo :: forall a b. Observable a -> Observable b -> Observable b 273 | ``` 274 | 275 | Maps each value of the Observable (arg1) to the same inner Observable (arg2), 276 | then flattens the result. 277 |  ![marble diagram](http://reactivex.io/documentation/operators/images/flatMap.c.png) 278 | 279 | #### `pairwise` 280 | 281 | ``` purescript 282 | pairwise :: forall a. Observable a -> Observable (Array a) 283 | ``` 284 | 285 | Puts the current value and previous value together as an array, and emits that. 286 | ![marble diagram](http://reactivex.io/rxjs/img/pairwise.png) 287 | 288 | #### `partition` 289 | 290 | ``` purescript 291 | partition :: forall a. (a -> Boolean) -> Observable a -> Array (Observable a) 292 | ``` 293 | 294 | Given a predicate function (arg1), and an Observable (arg2), it outputs a 295 | two element array of partitioned values 296 | (i.e., [ Observable valuesThatPassPredicate, Observable valuesThatFailPredicate ]). 297 | ![marble diagram](http://reactivex.io/rxjs/img/partition.png) 298 | 299 | #### `scan` 300 | 301 | ``` purescript 302 | scan :: forall a b. (a -> b -> b) -> b -> Observable a -> Observable b 303 | ``` 304 | 305 | Given an accumulator function (arg1), an initial value (arg2), and 306 | a source Observable (arg3), it returns an Observable that emits the current 307 | accumlation whenever the source emits a value. 308 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/scanSeed.png) 309 | 310 | #### `switchMap` 311 | 312 | ``` purescript 313 | switchMap :: forall a b. Observable a -> (a -> Observable b) -> Observable b 314 | ``` 315 | 316 | Projects each source value to an Observable which is merged in the output 317 | Observable, emitting values only from the most recently projected Observable. 318 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/switchMap.png) 319 | 320 | #### `switchMapTo` 321 | 322 | ``` purescript 323 | switchMapTo :: forall a b. Observable a -> Observable b -> Observable b 324 | ``` 325 | 326 | It's like switchMap, but maps each value to the same inner Observable. 327 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/switchMap.png) 328 | 329 | #### `window` 330 | 331 | ``` purescript 332 | window :: forall a b. Observable a -> Observable b -> Observable (Observable a) 333 | ``` 334 | 335 | It's like buffer, but emits a nested Observable instead of an array. 336 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/window8.png) 337 | 338 | #### `windowCount` 339 | 340 | ``` purescript 341 | windowCount :: forall a. Int -> Int -> Observable a -> Observable (Observable a) 342 | ``` 343 | 344 | It's like bufferCount, but emits a nested Observable instead of an array. 345 | 346 | #### `windowTime` 347 | 348 | ``` purescript 349 | windowTime :: forall a. Int -> Int -> Observable a -> Observable (Observable a) 350 | ``` 351 | 352 | It's like bufferTime, but emits a nested Observable instead of an array, 353 | and it doesn't take a maximum size parameter. arg1 is how long to 354 | buffer items into a new Observable, arg2 is the when the next buffer should begin, 355 | and arg3 is the source Observable. 356 | 357 | #### `windowToggle` 358 | 359 | ``` purescript 360 | windowToggle :: forall a b c. (Observable a) -> (Observable b) -> (b -> Observable c) -> (Observable (Array a)) 361 | ``` 362 | 363 | It's like bufferToggle, but emits a nested Observable instead of an array. 364 | 365 | #### `windowWhen` 366 | 367 | ``` purescript 368 | windowWhen :: forall a b. Observable a -> Observable b -> Observable (Observable a) 369 | ``` 370 | 371 | It's like bufferWhen, but emits a nested Observable instead of an array. 372 | 373 | #### `audit` 374 | 375 | ``` purescript 376 | audit :: forall a b. Observable a -> (a -> Observable b) -> Observable a 377 | ``` 378 | 379 | It's like auditTime, but the silencing duration is determined by a second Observable. 380 | ![marble diagram](http://reactivex.io/rxjs/img/audit.png) 381 | 382 | #### `ajax` 383 | 384 | ``` purescript 385 | ajax :: forall e. String -> Eff e (Observable Response) 386 | ``` 387 | 388 | #### `ajaxWithBody` 389 | 390 | ``` purescript 391 | ajaxWithBody :: forall e. Request -> Eff e (Observable Response) 392 | ``` 393 | 394 | #### `auditTime` 395 | 396 | ``` purescript 397 | auditTime :: forall a. Int -> Observable a -> Observable a 398 | ``` 399 | 400 | Ignores source values for duration milliseconds, 401 | then emits the most recent value from the source Observable, then repeats this process. 402 | ![marble diagram](http://reactivex.io/rxjs/img/auditTime.png) 403 | 404 | #### `debounce` 405 | 406 | ``` purescript 407 | debounce :: forall a. Observable a -> (a -> Observable Int) -> Observable a 408 | ``` 409 | 410 | It's like debounceTime, but the time span of emission silence is determined 411 | by a second Observable. Allows for a variable debounce rate. 412 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/debounce.f.png) 413 | 414 | #### `debounceTime` 415 | 416 | ``` purescript 417 | debounceTime :: forall a. Int -> Observable a -> Observable a 418 | ``` 419 | 420 | It's like delay, but passes only the most recent value from each burst of emissions. 421 | 422 | #### `distinct` 423 | 424 | ``` purescript 425 | distinct :: forall a. Observable a -> Observable a 426 | ``` 427 | 428 | Returns an Observable that emits all items emitted by the source Observable 429 | that are distinct by comparison from previous items. 430 | ![marble diagram](http://reactivex.io/documentation/operators/images/distinct.png) 431 | 432 | #### `distinctUntilChanged` 433 | 434 | ``` purescript 435 | distinctUntilChanged :: forall a. Observable a -> Observable a 436 | ``` 437 | 438 | Returns an Observable that emits all items emitted by the source Observable 439 | that are distinct by comparison from the previous item. 440 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/distinctUntilChanged.key.png) 441 | 442 | #### `elementAt` 443 | 444 | ``` purescript 445 | elementAt :: forall a. Observable a -> Int -> Observable a 446 | ``` 447 | 448 | Emits the single value at the specified index in a sequence of emissions 449 | from the source Observable. 450 | 451 | #### `filter` 452 | 453 | ``` purescript 454 | filter :: forall a. (a -> Boolean) -> Observable a -> Observable a 455 | ``` 456 | 457 | Filter items emitted by the source Observable by only emitting those that 458 | satisfy a specified predicate. 459 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/filter.png) 460 | 461 | #### `ignoreElements` 462 | 463 | ``` purescript 464 | ignoreElements :: forall a. Observable a -> Observable a 465 | ``` 466 | 467 | Ignores all items emitted by the source Observable and only passes calls of complete or error. 468 | ![marble diagram](http://reactivex.io/rxjs/img/ignoreElements.png) 469 | 470 | #### `first` 471 | 472 | ``` purescript 473 | first :: forall a. Observable a -> (a -> Boolean) -> Observable a 474 | ``` 475 | 476 | Returns an Observable that emits only the first item emitted by the source 477 | Observable that satisfies the given predicate. 478 | 479 | #### `last` 480 | 481 | ``` purescript 482 | last :: forall a. Observable a -> (a -> Boolean) -> Observable a 483 | ``` 484 | 485 | Returns an Observable that emits only the last item emitted by the source 486 | Observable that that satisfies the given predicate. 487 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/last.png) 488 | 489 | #### `sample` 490 | 491 | ``` purescript 492 | sample :: forall a b. Observable a -> Observable b -> Observable a 493 | ``` 494 | 495 | It's like sampleTime, but samples whenever the notifier Observable emits something. 496 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/sample.o.png) 497 | 498 | #### `isEmpty` 499 | 500 | ``` purescript 501 | isEmpty :: forall a. Observable a -> Observable Boolean 502 | ``` 503 | 504 | Tests whether this `Observable` emits no elements. 505 | 506 | returns an Observable emitting one single Boolean, which is `true` if this `Observable` 507 | emits no elements, and `false` otherwise. 508 | 509 | #### `sampleTime` 510 | 511 | ``` purescript 512 | sampleTime :: forall a. Int -> Observable a -> Observable a 513 | ``` 514 | 515 | Periodically looks at the source Observable and emits whichever 516 | value it has most recently emitted since the previous sampling, unless the source has not emitted anything since the previous sampling. 517 | 518 | #### `share` 519 | 520 | ``` purescript 521 | share :: forall a. Observable a -> Observable a 522 | ``` 523 | 524 | Returns a new Observable that multicasts (shares) the original Observable. As long a 525 | there is more than 1 Subscriber, this Observable will be subscribed and emitting data. 526 | When all subscribers have unsubscribed it will unsubscribe from the source Observable. 527 | 528 | This is an alias for `publish().refCount()` 529 | 530 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/publishRefCount.png) 531 | 532 | returns an Observable that upon connection causes the source Observable to emit items to its Subscribers 533 | 534 | #### `skip` 535 | 536 | ``` purescript 537 | skip :: forall a. Int -> Observable a -> Observable a 538 | ``` 539 | 540 | Returns an Observable that skips n items emitted by an Observable. 541 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/skip.png) 542 | 543 | #### `skipUntil` 544 | 545 | ``` purescript 546 | skipUntil :: forall a b. Observable a -> Observable b -> Observable a 547 | ``` 548 | 549 | Returns an Observable that skips items emitted by the source Observable until a second Observable emits an item. 550 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/skipUntil.png) 551 | 552 | #### `skipWhile` 553 | 554 | ``` purescript 555 | skipWhile :: forall a. (a -> Boolean) -> Observable a -> Observable a 556 | ``` 557 | 558 | Returns an Observable that skips all items emitted 559 | by the source Observable as long as a specified condition holds true, 560 | but emits all further source items as soon as the condition becomes false. 561 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/skipWhile.png) 562 | 563 | #### `take` 564 | 565 | ``` purescript 566 | take :: forall a. Int -> Observable a -> Observable a 567 | ``` 568 | 569 | Emits only the first n values emitted by the source Observable. 570 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/take.png) 571 | 572 | #### `takeUntil` 573 | 574 | ``` purescript 575 | takeUntil :: forall a b. Observable a -> Observable b -> Observable a 576 | ``` 577 | 578 | Lets values pass until a second Observable emits something. Then, it completes. 579 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/takeUntil.png" alt="" 580 | 581 | #### `takeWhile` 582 | 583 | ``` purescript 584 | takeWhile :: forall a. (a -> Boolean) -> Observable a -> Observable a 585 | ``` 586 | 587 | Emits values emitted by the source Observable so long as each value satisfies 588 | the given predicate, and then completes as soon as this predicate is not satisfied. 589 | 590 | #### `throttle` 591 | 592 | ``` purescript 593 | throttle :: forall a b. Observable a -> (a -> Observable b) -> Observable a 594 | ``` 595 | 596 | It's like throttleTime, but the silencing duration is determined by a second Observable. 597 | ![marble diagram](http://reactivex.io/rxjs/img/throttle.png" width="640" height="195"> 598 | 599 | #### `throttleTime` 600 | 601 | ``` purescript 602 | throttleTime :: forall a. Int -> Observable a -> Observable a 603 | ``` 604 | 605 | Emits a value from the source Observable, then ignores subsequent source values 606 | for duration milliseconds, then repeats this process. 607 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/throttleWithTimeout.png) 608 | 609 | #### `combineLatest` 610 | 611 | ``` purescript 612 | combineLatest :: forall a b c. (a -> b -> c) -> Observable a -> Observable b -> Observable c 613 | ``` 614 | 615 | An Observable of projected values from the most recent values from each input Observable. 616 | ![marble diagram](http://reactivex.io/documentation/operators/images/combineLatest.png) 617 | 618 | #### `combineLatest3` 619 | 620 | ``` purescript 621 | combineLatest3 :: forall a b c d. (a -> b -> c -> d) -> Observable a -> Observable b -> Observable c -> Observable d 622 | ``` 623 | 624 | #### `concat` 625 | 626 | ``` purescript 627 | concat :: forall a. Observable a -> Observable a -> Observable a 628 | ``` 629 | 630 | Concatenates two Observables together by sequentially emitting their values, one Observable after the other. 631 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/concat.png) 632 | 633 | #### `concatAll` 634 | 635 | ``` purescript 636 | concatAll :: forall a. Observable (Observable a) -> Observable a 637 | ``` 638 | 639 | Converts a higher-order Observable into a first-order Observable by concatenating the inner Observables in order. 640 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/concat.png) 641 | 642 | #### `exhaust` 643 | 644 | ``` purescript 645 | exhaust :: forall a. Observable (Observable a) -> Observable a 646 | ``` 647 | 648 | Flattens an Observable-of-Observables by dropping the next inner Observables 649 | while the current inner is still executing. 650 | ![marble diagram](http://reactivex.io/rxjs/img/exhaust.png) 651 | 652 | #### `merge` 653 | 654 | ``` purescript 655 | merge :: forall a. Observable a -> Observable a -> Observable a 656 | ``` 657 | 658 | Creates an output Observable which concurrently emits all values from each input Observable. 659 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/merge.png) 660 | 661 | #### `mergeAll` 662 | 663 | ``` purescript 664 | mergeAll :: forall a. Observable (Observable a) -> Observable a 665 | ``` 666 | 667 | Converts a higher-order Observable into a first-order Observable 668 | which concurrently delivers all values that are emitted on the inner Observables. 669 | ![marble diagram](http://reactivex.io/documentation/operators/images/mergeAll.png) 670 | 671 | #### `race` 672 | 673 | ``` purescript 674 | race :: forall a. Array (Observable a) -> Observable a 675 | ``` 676 | 677 | Returns an Observable that mirrors the first source Observable to emit an 678 | item from the array of Observables. 679 | 680 | #### `startWith` 681 | 682 | ``` purescript 683 | startWith :: forall a. a -> Observable a -> Observable a 684 | ``` 685 | 686 | Returns an Observable that emits the item given before 687 | it begins to emit items emitted by the source Observable. 688 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/startWith.png) 689 | 690 | #### `startWithMany` 691 | 692 | ``` purescript 693 | startWithMany :: forall f a. Foldable f => f a -> Observable a -> Observable a 694 | ``` 695 | 696 | Returns an Observable that emits the items in the given Foldable before 697 | it begins to emit items emitted by the source Observable. 698 | 699 | #### `withLatestFrom` 700 | 701 | ``` purescript 702 | withLatestFrom :: forall a b c. (a -> b -> c) -> Observable a -> Observable b -> Observable c 703 | ``` 704 | 705 | Combines each value from the source Observables using a project function to 706 | determine the value to be emitted on the output Observable. 707 | ![marble diagram](https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/withLatestFrom.png" alt=""> 708 | 709 | #### `zip` 710 | 711 | ``` purescript 712 | zip :: forall a. Array (Observable a) -> Observable (Array a) 713 | ``` 714 | 715 | Waits for each Observable to emit a value. Once this occurs, all values 716 | with the corresponding index will be emitted. This will continue until at 717 | least one inner observable completes. 718 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/zip.i.png) 719 | 720 | #### `catch` 721 | 722 | ``` purescript 723 | catch :: forall a. (Observable a) -> (Error -> Observable a) -> (Observable a) 724 | ``` 725 | 726 | ![marble diagram](http://reactivex.io/documentation/operators/images/catch.js.png) 727 | 728 | #### `retry` 729 | 730 | ``` purescript 731 | retry :: forall a. Int -> Observable a -> Observable a 732 | ``` 733 | 734 | If the source Observable calls error, this method will resubscribe to the 735 | source Observable n times rather than propagating the error call. 736 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/retry.png) 737 | 738 | #### `defaultIfEmpty` 739 | 740 | ``` purescript 741 | defaultIfEmpty :: forall a. Observable a -> a -> Observable a 742 | ``` 743 | 744 | Returns an Observable that emits the items emitted by the source Observable or a specified default item 745 | if the source Observable is empty. 746 | 747 | ![marble diagram](http://reactivex.io/documentation/operators/images/defaultIfEmpty.c.png) 748 | 749 | takes a defaultValue which is the item to emit if the source Observable emits no items. 750 | 751 | returns an Observable that emits either the specified default item if the source Observable emits no 752 | items, or the items emitted by the source Observable 753 | 754 | #### `delay` 755 | 756 | ``` purescript 757 | delay :: forall a. Int -> Observable a -> Observable a 758 | ``` 759 | 760 | Time shifts each item by some specified amount of milliseconds. 761 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/delay.png) 762 | 763 | #### `delayWhen` 764 | 765 | ``` purescript 766 | delayWhen :: forall a b. Observable a -> (a -> Observable b) -> Observable a 767 | ``` 768 | 769 | Delays the emission of items from the source Observable by a given time 770 | span determined by the emissions of another Observable. 771 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/delay.o.png) 772 | 773 | #### `dematerialize` 774 | 775 | ``` purescript 776 | dematerialize :: forall a. Observable (Notification a) -> Observable a 777 | ``` 778 | 779 | Returns an Observable that reverses the effect of `materialize` by 780 | `Notification` objects emitted by the source Observable into the items 781 | or notifications they represent. 782 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/dematerialize.png) 783 | 784 | #### `materialize` 785 | 786 | ``` purescript 787 | materialize :: forall a. Observable a -> Observable (Notification a) 788 | ``` 789 | 790 | Turns all of the notifications from a source Observable into onNext emissions, 791 | and marks them with their original notification types within `Notification` objects. 792 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/materialize.png) 793 | 794 | #### `performEach` 795 | 796 | ``` purescript 797 | performEach :: forall a e. Observable a -> (a -> Eff e Unit) -> Eff e (Observable a) 798 | ``` 799 | 800 | Performs the effect on each value of the Observable. An alias for `do`. 801 | Useful for testing (transparently performing an effect outside of a subscription). 802 | 803 | #### `toArray` 804 | 805 | ``` purescript 806 | toArray :: forall a. Observable a -> Observable (Array a) 807 | ``` 808 | 809 | Returns an Observable that emits a single item, a list composed of all the items emitted by the source Observable. 810 | ![marble diagram](https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/toList.png) 811 | 812 | #### `count` 813 | 814 | ``` purescript 815 | count :: forall a. Observable a -> Observable Int 816 | ``` 817 | 818 | Counts the number of emissions on the source and emits that number when the source completes. 819 | 820 | #### `reduce` 821 | 822 | ``` purescript 823 | reduce :: forall a b. (a -> b -> b) -> b -> Observable a -> Observable b 824 | ``` 825 | 826 | Applies an accumulator function over the source Observable, and returns the accumulated 827 | result when the source completes, given a seed value. 828 | 829 | #### `unwrap` 830 | 831 | ``` purescript 832 | unwrap :: forall a e. Observable (Eff e a) -> Eff e (Observable a) 833 | ``` 834 | 835 | Run an Observable of effects 836 | 837 | #### `Response` 838 | 839 | ``` purescript 840 | type Response = { body :: String, status :: Int, responseType :: String } 841 | ``` 842 | 843 | #### `Request` 844 | 845 | ``` purescript 846 | type Request = { url :: String, body :: String, timeout :: Int, headers :: StrMap String, crossDomain :: Boolean, responseType :: String, method :: String } 847 | ``` 848 | 849 | 850 | -------------------------------------------------------------------------------- /generated-docs/RxJS/ReplaySubject.md: -------------------------------------------------------------------------------- 1 | ## Module RxJS.ReplaySubject 2 | 3 | #### `ReplaySubject` 4 | 5 | ``` purescript 6 | data ReplaySubject :: Type -> Type 7 | ``` 8 | 9 | Please see [RxJS Version 5.* documentation](http://reactivex.io/rxjs/) for 10 | additional details on proper usage of the library. 11 | 12 | ##### Instances 13 | ``` purescript 14 | Functor ReplaySubject 15 | Apply ReplaySubject 16 | Applicative ReplaySubject 17 | Bind ReplaySubject 18 | Monad ReplaySubject 19 | Semigroup (ReplaySubject a) 20 | Alt ReplaySubject 21 | Plus ReplaySubject 22 | Alternative ReplaySubject 23 | MonadZero ReplaySubject 24 | MonadPlus ReplaySubject 25 | ``` 26 | 27 | #### `observeOn` 28 | 29 | ``` purescript 30 | observeOn :: forall a. Scheduler -> ReplaySubject a -> ReplaySubject a 31 | ``` 32 | 33 | Makes every `next` call run in the new Scheduler. 34 | 35 | #### `subscribeOn` 36 | 37 | ``` purescript 38 | subscribeOn :: forall a. Scheduler -> ReplaySubject a -> ReplaySubject a 39 | ``` 40 | 41 | Makes subscription happen on a given Scheduler. 42 | 43 | #### `subscribe` 44 | 45 | ``` purescript 46 | subscribe :: forall a e. Subscriber a -> ReplaySubject a -> Eff e Subscription 47 | ``` 48 | 49 | Subscribing to an ReplaySubject is like calling a function, providing 50 | `next`, `error` and `completed` effects to which the data will be delivered. 51 | 52 | #### `subscribeNext` 53 | 54 | ``` purescript 55 | subscribeNext :: forall a e. (a -> Eff e Unit) -> ReplaySubject a -> Eff e Subscription 56 | ``` 57 | 58 | #### `just` 59 | 60 | ``` purescript 61 | just :: forall a. a -> ReplaySubject a 62 | ``` 63 | 64 | Creates an ReplaySubject that emits the value specify, 65 | and then emits a complete notification. An alias for `of`. 66 | 67 | #### `next` 68 | 69 | ``` purescript 70 | next :: forall a e. a -> ReplaySubject a -> Eff e Unit 71 | ``` 72 | 73 | Send a new value to a ReplaySubject 74 | 75 | #### `send` 76 | 77 | ``` purescript 78 | send :: forall a e. a -> ReplaySubject a -> Eff e Unit 79 | ``` 80 | 81 | An alias for next 82 | 83 | #### `asObservable` 84 | 85 | ``` purescript 86 | asObservable :: forall a. ReplaySubject a -> Observable a 87 | ``` 88 | 89 | Create an Observable from a ReplaySubject 90 | 91 | #### `buffer` 92 | 93 | ``` purescript 94 | buffer :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject (Array a) 95 | ``` 96 | 97 | Collects values from the first ReplaySubject into an Array, and emits that array only when 98 | second ReplaySubject emits. 99 | 100 | #### `bufferCount` 101 | 102 | ``` purescript 103 | bufferCount :: forall a. Int -> Int -> ReplaySubject a -> ReplaySubject (Array a) 104 | ``` 105 | 106 | Collects values from the past as an array, emits that array when 107 | its size (arg1) reaches the specified buffer size, and starts a new buffer. 108 | The new buffer starts with nth (arg2) element of the ReplaySubject counting 109 | from the beginning of the *last* buffer. 110 | 111 | #### `bufferToggle` 112 | 113 | ``` purescript 114 | bufferToggle :: forall a b c. (ReplaySubject a) -> (ReplaySubject b) -> (b -> ReplaySubject c) -> (ReplaySubject (Array a)) 115 | ``` 116 | 117 | Collects values from the source ReplaySubject (arg1) as an array. Starts collecting only when 118 | the opening (arg2) ReplaySubject emits, and calls the closingSelector function (arg3) to get an ReplaySubject 119 | that decides when to close the buffer. Another buffer opens when the 120 | opening ReplaySubject emits its next value. 121 | 122 | #### `bufferWhen` 123 | 124 | ``` purescript 125 | bufferWhen :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject (Array a) 126 | ``` 127 | 128 | Collects values from the past as an array. When it starts collecting values, 129 | it calls a function that returns an ReplaySubject that emits to close the 130 | buffer and restart collecting. 131 | 132 | #### `concatMap` 133 | 134 | ``` purescript 135 | concatMap :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject b 136 | ``` 137 | 138 | Equivalent to mergeMap (a.k.a, `>>=`) EXCEPT that, unlike mergeMap, 139 | the next bind will not run until the ReplaySubject generated by the projection function (arg2) 140 | completes. That is, composition is sequential, not concurrent. 141 | Warning: if source values arrive endlessly and faster than their corresponding 142 | inner ReplaySubjects can complete, it will result in memory issues as inner 143 | ReplaySubjects amass in an unbounded buffer waiting for their turn to be subscribed to. 144 | 145 | #### `concatMapTo` 146 | 147 | ``` purescript 148 | concatMapTo :: forall a b c. ReplaySubject a -> ReplaySubject b -> (a -> b -> ReplaySubject c) -> ReplaySubject c 149 | ``` 150 | 151 | The type signature explains it best. Warning: Like `concatMap`, composition is sequential. 152 | 153 | #### `exhaustMap` 154 | 155 | ``` purescript 156 | exhaustMap :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject b 157 | ``` 158 | 159 | It's Like concatMap (a.k.a, `>>=`) EXCEPT that it ignores every new projected 160 | ReplaySubject if the previous projected ReplaySubject has not yet completed. 161 | 162 | #### `expand` 163 | 164 | ``` purescript 165 | expand :: forall a. ReplaySubject a -> (a -> ReplaySubject a) -> ReplaySubject a 166 | ``` 167 | 168 | It's similar to mergeMap, but applies the projection function to every source 169 | value as well as every output value. It's recursive. 170 | 171 | #### `groupBy` 172 | 173 | ``` purescript 174 | groupBy :: forall a b. (a -> b) -> ReplaySubject a -> ReplaySubject (ReplaySubject a) 175 | ``` 176 | 177 | Groups the items emitted by an ReplaySubject (arg2) according to the value 178 | returned by the grouping function (arg1). Each group becomes its own 179 | ReplaySubject. 180 | 181 | #### `mapTo` 182 | 183 | ``` purescript 184 | mapTo :: forall a b. b -> ReplaySubject a -> ReplaySubject b 185 | ``` 186 | 187 | Emits the given constant value on the output ReplaySubject every time 188 | the source ReplaySubject emits a value. 189 | 190 | #### `mergeMap` 191 | 192 | ``` purescript 193 | mergeMap :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject b 194 | ``` 195 | 196 | Maps each value to an ReplaySubject, then flattens all of these ReplaySubjects 197 | using mergeAll. It's just monadic `bind`. 198 | 199 | #### `mergeMapTo` 200 | 201 | ``` purescript 202 | mergeMapTo :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject b 203 | ``` 204 | 205 | Maps each value of the ReplaySubject (arg1) to the same inner ReplaySubject (arg2), 206 | then flattens the result. 207 | 208 | #### `pairwise` 209 | 210 | ``` purescript 211 | pairwise :: forall a. ReplaySubject a -> ReplaySubject (Array a) 212 | ``` 213 | 214 | Puts the current value and previous value together as an array, and emits that. 215 | 216 | #### `partition` 217 | 218 | ``` purescript 219 | partition :: forall a. (a -> Boolean) -> ReplaySubject a -> Array (ReplaySubject a) 220 | ``` 221 | 222 | Given a predicate function (arg1), and an ReplaySubject (arg2), it outputs a 223 | two element array of partitioned values 224 | (i.e., [ ReplaySubject valuesThatPassPredicate, ReplaySubject valuesThatFailPredicate ]). 225 | 226 | #### `scan` 227 | 228 | ``` purescript 229 | scan :: forall a b. (a -> b -> b) -> b -> ReplaySubject a -> ReplaySubject b 230 | ``` 231 | 232 | Given an accumulator function (arg1), an initial value (arg2), and 233 | a source ReplaySubject (arg3), it returns an ReplaySubject that emits the current 234 | accumlation whenever the source emits a value. 235 | 236 | #### `switchMap` 237 | 238 | ``` purescript 239 | switchMap :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject b 240 | ``` 241 | 242 | Projects each source value to an ReplaySubject which is merged in the output 243 | ReplaySubject, emitting values only from the most recently projected ReplaySubject. 244 | 245 | #### `switchMapTo` 246 | 247 | ``` purescript 248 | switchMapTo :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject b 249 | ``` 250 | 251 | It's like switchMap, but maps each value to the same inner ReplaySubject. 252 | 253 | #### `window` 254 | 255 | ``` purescript 256 | window :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject (ReplaySubject a) 257 | ``` 258 | 259 | It's like buffer, but emits a nested ReplaySubject instead of an array. 260 | 261 | #### `windowCount` 262 | 263 | ``` purescript 264 | windowCount :: forall a. Int -> Int -> ReplaySubject a -> ReplaySubject (ReplaySubject a) 265 | ``` 266 | 267 | It's like bufferCount, but emits a nested ReplaySubject instead of an array. 268 | 269 | #### `windowTime` 270 | 271 | ``` purescript 272 | windowTime :: forall a. Int -> Int -> ReplaySubject a -> ReplaySubject (ReplaySubject a) 273 | ``` 274 | 275 | It's like bufferTime, but emits a nested ReplaySubject instead of an array, 276 | and it doesn't take a maximum size parameter. arg1 is how long to 277 | buffer items into a new ReplaySubject, arg2 is the when the next buffer should begin, 278 | and arg3 is the source ReplaySubject. 279 | 280 | #### `windowToggle` 281 | 282 | ``` purescript 283 | windowToggle :: forall a b c. (ReplaySubject a) -> (ReplaySubject b) -> (b -> ReplaySubject c) -> (ReplaySubject (Array a)) 284 | ``` 285 | 286 | It's like bufferToggle, but emits a nested ReplaySubject instead of an array. 287 | 288 | #### `windowWhen` 289 | 290 | ``` purescript 291 | windowWhen :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject (ReplaySubject a) 292 | ``` 293 | 294 | It's like bufferWhen, but emits a nested ReplaySubject instead of an array. 295 | 296 | #### `audit` 297 | 298 | ``` purescript 299 | audit :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject a 300 | ``` 301 | 302 | It's like auditTime, but the silencing duration is determined by a second ReplaySubject. 303 | 304 | #### `auditTime` 305 | 306 | ``` purescript 307 | auditTime :: forall a. Int -> ReplaySubject a -> ReplaySubject a 308 | ``` 309 | 310 | Ignores source values for duration milliseconds, 311 | then emits the most recent value from the source ReplaySubject, then repeats this process. 312 | 313 | #### `debounce` 314 | 315 | ``` purescript 316 | debounce :: forall a. ReplaySubject a -> (a -> ReplaySubject Int) -> ReplaySubject a 317 | ``` 318 | 319 | It's like debounceTime, but the time span of emission silence is determined 320 | by a second ReplaySubject. Allows for a variable debounce rate. 321 | 322 | #### `debounceTime` 323 | 324 | ``` purescript 325 | debounceTime :: forall a. Int -> ReplaySubject a -> ReplaySubject a 326 | ``` 327 | 328 | It's like delay, but passes only the most recent value from each burst of emissions. 329 | 330 | #### `distinct` 331 | 332 | ``` purescript 333 | distinct :: forall a. ReplaySubject a -> ReplaySubject a 334 | ``` 335 | 336 | Returns an ReplaySubject that emits all items emitted by the source ReplaySubject 337 | that are distinct by comparison from previous items. 338 | 339 | #### `distinctUntilChanged` 340 | 341 | ``` purescript 342 | distinctUntilChanged :: forall a. ReplaySubject a -> ReplaySubject a 343 | ``` 344 | 345 | Returns an ReplaySubject that emits all items emitted by the source ReplaySubject 346 | that are distinct by comparison from the previous item. 347 | 348 | #### `elementAt` 349 | 350 | ``` purescript 351 | elementAt :: forall a. ReplaySubject a -> Int -> ReplaySubject a 352 | ``` 353 | 354 | Emits the single value at the specified index in a sequence of emissions 355 | from the source ReplaySubject. 356 | 357 | #### `filter` 358 | 359 | ``` purescript 360 | filter :: forall a. (a -> Boolean) -> ReplaySubject a -> ReplaySubject a 361 | ``` 362 | 363 | Filter items emitted by the source ReplaySubject by only emitting those that 364 | satisfy a specified predicate. 365 | 366 | #### `ignoreElements` 367 | 368 | ``` purescript 369 | ignoreElements :: forall a. ReplaySubject a -> ReplaySubject a 370 | ``` 371 | 372 | Ignores all items emitted by the source ReplaySubject and only passes calls of complete or error. 373 | 374 | #### `last` 375 | 376 | ``` purescript 377 | last :: forall a. ReplaySubject a -> ReplaySubject a 378 | ``` 379 | 380 | Returns an ReplaySubject that emits only the last item emitted by the source ReplaySubject. 381 | 382 | #### `sample` 383 | 384 | ``` purescript 385 | sample :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject a 386 | ``` 387 | 388 | It's like sampleTime, but samples whenever the notifier ReplaySubject emits something. 389 | 390 | #### `sampleTime` 391 | 392 | ``` purescript 393 | sampleTime :: forall a. Int -> ReplaySubject a -> ReplaySubject a 394 | ``` 395 | 396 | Periodically looks at the source ReplaySubject and emits whichever 397 | value it has most recently emitted since the previous sampling, unless the source has not emitted anything since the previous sampling. 398 | 399 | #### `skip` 400 | 401 | ``` purescript 402 | skip :: forall a. Int -> ReplaySubject a -> ReplaySubject a 403 | ``` 404 | 405 | Returns an ReplaySubject that skips n items emitted by an ReplaySubject. 406 | 407 | #### `skipUntil` 408 | 409 | ``` purescript 410 | skipUntil :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject a 411 | ``` 412 | 413 | Returns an ReplaySubject that skips items emitted by the source ReplaySubject until a second ReplaySubject emits an item. 414 | 415 | #### `skipWhile` 416 | 417 | ``` purescript 418 | skipWhile :: forall a. (a -> Boolean) -> ReplaySubject a -> ReplaySubject a 419 | ``` 420 | 421 | Returns an ReplaySubject that skips all items emitted 422 | by the source ReplaySubject as long as a specified condition holds true, 423 | but emits all further source items as soon as the condition becomes false. 424 | 425 | #### `take` 426 | 427 | ``` purescript 428 | take :: forall a. Int -> ReplaySubject a -> ReplaySubject a 429 | ``` 430 | 431 | Emits only the first n values emitted by the source ReplaySubject. 432 | 433 | #### `takeUntil` 434 | 435 | ``` purescript 436 | takeUntil :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject a 437 | ``` 438 | 439 | Lets values pass until a second ReplaySubject emits something. Then, it completes. 440 | 441 | #### `takeWhile` 442 | 443 | ``` purescript 444 | takeWhile :: forall a. (a -> Boolean) -> ReplaySubject a -> ReplaySubject a 445 | ``` 446 | 447 | Emits values emitted by the source ReplaySubject so long as each value satisfies 448 | the given predicate, and then completes as soon as this predicate is not satisfied. 449 | 450 | #### `throttle` 451 | 452 | ``` purescript 453 | throttle :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject a 454 | ``` 455 | 456 | It's like throttleTime, but the silencing duration is determined by a second ReplaySubject. 457 | 458 | #### `throttleTime` 459 | 460 | ``` purescript 461 | throttleTime :: forall a. Int -> ReplaySubject a -> ReplaySubject a 462 | ``` 463 | 464 | Emits a value from the source ReplaySubject, then ignores subsequent source values 465 | for duration milliseconds, then repeats this process. 466 | 467 | #### `combineLatest` 468 | 469 | ``` purescript 470 | combineLatest :: forall a b c. (a -> b -> c) -> ReplaySubject a -> ReplaySubject b -> ReplaySubject c 471 | ``` 472 | 473 | An ReplaySubject of projected values from the most recent values from each input ReplaySubject. 474 | 475 | #### `concat` 476 | 477 | ``` purescript 478 | concat :: forall a. ReplaySubject a -> ReplaySubject a -> ReplaySubject a 479 | ``` 480 | 481 | Concatenates two ReplaySubjects together by sequentially emitting their values, one ReplaySubject after the other. 482 | 483 | #### `concatAll` 484 | 485 | ``` purescript 486 | concatAll :: forall a. ReplaySubject (ReplaySubject a) -> ReplaySubject a 487 | ``` 488 | 489 | Converts a higher-order ReplaySubject into a first-order ReplaySubject by concatenating the inner ReplaySubjects in order. 490 | 491 | #### `exhaust` 492 | 493 | ``` purescript 494 | exhaust :: forall a. ReplaySubject (ReplaySubject a) -> ReplaySubject a 495 | ``` 496 | 497 | Flattens an ReplaySubject-of-ReplaySubjects by dropping the next inner ReplaySubjects 498 | while the current inner is still executing. 499 | 500 | #### `merge` 501 | 502 | ``` purescript 503 | merge :: forall a. ReplaySubject a -> ReplaySubject a -> ReplaySubject a 504 | ``` 505 | 506 | Creates an output ReplaySubject which concurrently emits all values from each input ReplaySubject. 507 | 508 | #### `mergeAll` 509 | 510 | ``` purescript 511 | mergeAll :: forall a. ReplaySubject (ReplaySubject a) -> ReplaySubject a 512 | ``` 513 | 514 | Converts a higher-order ReplaySubject into a first-order ReplaySubject 515 | which concurrently delivers all values that are emitted on the inner ReplaySubjects. 516 | 517 | #### `race` 518 | 519 | ``` purescript 520 | race :: forall a. Array (ReplaySubject a) -> ReplaySubject a 521 | ``` 522 | 523 | Returns an ReplaySubject that mirrors the first source ReplaySubject to emit an 524 | item from the array of ReplaySubjects. 525 | 526 | #### `startWith` 527 | 528 | ``` purescript 529 | startWith :: forall a. Array a -> ReplaySubject a -> ReplaySubject a 530 | ``` 531 | 532 | Returns an ReplaySubject that emits the items in the given Array before 533 | it begins to emit items emitted by the source ReplaySubject. 534 | 535 | #### `withLatestFrom` 536 | 537 | ``` purescript 538 | withLatestFrom :: forall a b c. (a -> b -> c) -> ReplaySubject a -> ReplaySubject b -> ReplaySubject c 539 | ``` 540 | 541 | Combines each value from the source ReplaySubjects using a project function to 542 | determine the value to be emitted on the output ReplaySubject. 543 | 544 | #### `zip` 545 | 546 | ``` purescript 547 | zip :: forall a. Array (ReplaySubject a) -> ReplaySubject (Array a) 548 | ``` 549 | 550 | Waits for each ReplaySubject to emit a value. Once this occurs, all values 551 | with the corresponding index will be emitted. This will continue until at 552 | least one inner ReplaySubject completes. 553 | 554 | #### `catch` 555 | 556 | ``` purescript 557 | catch :: forall a. (ReplaySubject a) -> (Error -> ReplaySubject a) -> (ReplaySubject a) 558 | ``` 559 | 560 | #### `retry` 561 | 562 | ``` purescript 563 | retry :: forall a. Int -> ReplaySubject a -> ReplaySubject a 564 | ``` 565 | 566 | If the source ReplaySubject calls error, this method will resubscribe to the 567 | source ReplaySubject n times rather than propagating the error call. 568 | 569 | #### `delay` 570 | 571 | ``` purescript 572 | delay :: forall a. Int -> ReplaySubject a -> ReplaySubject a 573 | ``` 574 | 575 | Time shifts each item by some specified amount of milliseconds. 576 | 577 | #### `delayWhen` 578 | 579 | ``` purescript 580 | delayWhen :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject a 581 | ``` 582 | 583 | Delays the emission of items from the source ReplaySubject by a given time 584 | span determined by the emissions of another ReplaySubject. 585 | 586 | #### `dematerialize` 587 | 588 | ``` purescript 589 | dematerialize :: forall a. ReplaySubject (Notification a) -> ReplaySubject a 590 | ``` 591 | 592 | #### `materialize` 593 | 594 | ``` purescript 595 | materialize :: forall a. ReplaySubject a -> ReplaySubject (Notification a) 596 | ``` 597 | 598 | #### `performEach` 599 | 600 | ``` purescript 601 | performEach :: forall a e. ReplaySubject a -> (a -> Eff e Unit) -> Eff e (ReplaySubject a) 602 | ``` 603 | 604 | Performs the effect on each value of the ReplaySubject. An alias for `do`. 605 | Useful for testing (transparently performing an effect outside of a subscription). 606 | 607 | #### `toArray` 608 | 609 | ``` purescript 610 | toArray :: forall a. ReplaySubject a -> ReplaySubject (Array a) 611 | ``` 612 | 613 | #### `count` 614 | 615 | ``` purescript 616 | count :: forall a. ReplaySubject a -> ReplaySubject Int 617 | ``` 618 | 619 | Counts the number of emissions on the source and emits that number when the source completes. 620 | 621 | 622 | -------------------------------------------------------------------------------- /generated-docs/RxJS/Scheduler.md: -------------------------------------------------------------------------------- 1 | ## Module RxJS.Scheduler 2 | 3 | #### `Scheduler` 4 | 5 | ``` purescript 6 | data Scheduler :: Type 7 | ``` 8 | 9 | Please see [RxJS Version 5.* documentation](http://reactivex.io/rxjs/) for 10 | additional details on proper usage of the library. 11 | 12 | #### `queue` 13 | 14 | ``` purescript 15 | queue :: Scheduler 16 | ``` 17 | 18 | #### `asap` 19 | 20 | ``` purescript 21 | asap :: Scheduler 22 | ``` 23 | 24 | #### `async` 25 | 26 | ``` purescript 27 | async :: Scheduler 28 | ``` 29 | 30 | #### `animationFrame` 31 | 32 | ``` purescript 33 | animationFrame :: Scheduler 34 | ``` 35 | 36 | 37 | -------------------------------------------------------------------------------- /generated-docs/RxJS/Subscriber.md: -------------------------------------------------------------------------------- 1 | ## Module RxJS.Subscriber 2 | 3 | #### `Subscriber` 4 | 5 | ``` purescript 6 | type Subscriber a = { next :: forall e. a -> Eff e Unit, error :: forall e. Error -> Eff e Unit, completed :: forall e. Unit -> Eff e Unit } 7 | ``` 8 | 9 | 10 | -------------------------------------------------------------------------------- /generated-docs/RxJS/Subscription.md: -------------------------------------------------------------------------------- 1 | ## Module RxJS.Subscription 2 | 3 | #### `Subscription` 4 | 5 | ``` purescript 6 | data Subscription :: Type 7 | ``` 8 | 9 | When you subscribe, you get back a Subscription, which represents the 10 | ongoing execution. 11 | 12 | #### `unsubscribe` 13 | 14 | ``` purescript 15 | unsubscribe :: forall e. Subscription -> Eff e Unit 16 | ``` 17 | 18 | Call unsubscribe() to cancel the execution. 19 | 20 | 21 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "purescript-rxjs", 3 | "version": "0.1.0", 4 | "description": "An un-opinionated wrapper around Reactive Extensions for JavaScript (v5.*).", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "start": "node node_modules/.bin/webpack-dev-server --inline --hot" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/jasonzoladz/purescript-rxjs.git" 15 | }, 16 | "keywords": [ 17 | "purescript-rxjs" 18 | ], 19 | "author": "Jason M. Zoladz", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/jasonzoladz/purescript-rxjs/issues" 23 | }, 24 | "homepage": "https://github.com/jasonzoladz/purescript-rxjs#readme", 25 | "devDependencies": { 26 | "purs-loader": "^2.1.1", 27 | "webpack": "^1.14.0", 28 | "webpack-dev-server": "^1.16.2" 29 | }, 30 | "dependencies": { 31 | "jquery": "^3.1.1", 32 | "rxjs": "^5.2.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/RxJS/AsyncSubject.js: -------------------------------------------------------------------------------- 1 | /* global exports */ 2 | "use strict"; 3 | 4 | // module RxJS.AsyncSubject 5 | 6 | var Rx = require('rxjs'); 7 | 8 | /**** Scheduling ****/ 9 | 10 | exports.observeOn = function(s){ 11 | return function(obs){ 12 | return obs.observeOn(s); 13 | }; 14 | } 15 | 16 | exports.subscribeOn = function(s){ 17 | return function(obs){ 18 | return obs.subscribeOn(s); 19 | }; 20 | } 21 | 22 | /**** Subscription ****/ 23 | 24 | exports.subscribe = function(sub){ 25 | return function(obs) { 26 | return function(){ 27 | return obs.subscribe( 28 | function(val){ sub.next(val)();}, 29 | function(err){ sub.error(err)();}, 30 | function(){sub.complete()();} 31 | ); 32 | }; 33 | }; 34 | } 35 | 36 | exports.subscribeObservableTo = function(obs){ 37 | return function(sub){ 38 | return function(){ 39 | return obs.subscribe(sub); 40 | }; 41 | }; 42 | } 43 | 44 | exports.subscribeNext = function (eff){ 45 | return function(obs){ 46 | return function(){ 47 | obs.subscribe( 48 | function(val){return eff(val)();} 49 | ); 50 | }; 51 | }; 52 | } 53 | 54 | /**** Creation Operators ****/ 55 | 56 | exports._empty = function(){ 57 | return new Rx.AsyncSubject(); 58 | } 59 | 60 | exports.just = function(val){ 61 | return new Rx.AsyncSubject(val); 62 | } 63 | 64 | /**** AsyncSubject Operators ****/ 65 | 66 | exports.asObservable = function(as){ 67 | return as.asObservable(); 68 | } 69 | 70 | /**** Transformation Operators ****/ 71 | 72 | exports.buffer = function(obs1){ 73 | return function(obs2){ 74 | return obs1.buffer(obs2); 75 | }; 76 | } 77 | 78 | exports.bufferCount = function(maxSize){ 79 | return function(startNewAt){ 80 | return function(obs){ 81 | return obs.bufferCount(maxSize, startNewAt); 82 | }; 83 | }; 84 | } 85 | 86 | exports.bufferTimeImpl = function(timespan, creationInterval, maxSize, obs){ 87 | return obs.bufferTime(timespan, creationInterval, maxSize); 88 | } 89 | 90 | exports.bufferToggleImpl = function(obs, openings, closingSelector){ 91 | return obs.bufferToggle(openings, closingSelector); 92 | } 93 | 94 | exports.bufferWhen = function(obs){ 95 | return function(closing){ 96 | return obs.bufferWhen(closing); 97 | }; 98 | } 99 | 100 | exports.concatMap = function(obs){ 101 | return function(f){ 102 | return obs.concatMap(f); 103 | }; 104 | } 105 | 106 | exports.concatMapTo = function(obs1){ 107 | return function(obs2){ 108 | return function(f){ 109 | return obs1.concatMapTo(obs2, function(a, b){ 110 | return f(a)(b); 111 | }); 112 | }; 113 | }; 114 | } 115 | 116 | exports.exhaustMap = function(obs){ 117 | return function(f){ 118 | return obs.exhaustMap(f); 119 | }; 120 | } 121 | 122 | exports.expand = function(obs){ 123 | return function(f){ 124 | return obs.expand(f); 125 | }; 126 | } 127 | 128 | exports.groupBy = function(f){ 129 | return function(obs){ 130 | return obs.groupBy(f); 131 | }; 132 | } 133 | 134 | exports._map = function(f){ 135 | return function(obs){ 136 | return obs.map(f); 137 | }; 138 | } 139 | 140 | exports.mapTo = function(val){ 141 | return function(obs1){ 142 | return obs1.mapTo(val); 143 | }; 144 | } 145 | 146 | exports.mergeMap = function(obs){ 147 | return function(f){ 148 | return obs.mergeMap(f); 149 | }; 150 | } 151 | 152 | 153 | exports.mergeMapTo = function(obs1){ 154 | return function(obs2){ 155 | return obs1.mergeMapTo(obs2); 156 | }; 157 | } 158 | 159 | exports.pairwise = function(obs){ 160 | return obs.pairwise(); 161 | } 162 | 163 | exports.partition = function(pred){ 164 | return function(obs){ 165 | return obs.partition(pred); 166 | }; 167 | } 168 | 169 | exports.scan = function scan(f) { 170 | return function(seed) { 171 | return function(ob) { 172 | return ob.scan(function(acc, value) { 173 | return f(value)(acc); 174 | }, seed); 175 | }; 176 | }; 177 | } 178 | 179 | exports.switchMap = function(obs){ 180 | return function(f){ 181 | return obs.switchMap(f); 182 | }; 183 | } 184 | 185 | exports.switchMapTo = function(obs1){ 186 | return function(obs2){ 187 | return obs1.switchMapTo(obs2); 188 | }; 189 | } 190 | 191 | exports.window = function(obs1){ 192 | return function(obs2){ 193 | return obs1.window(obs2); 194 | }; 195 | } 196 | 197 | exports.windowCount = function(maxSize){ 198 | return function(startNewAt){ 199 | return function(obs){ 200 | return obs.windowCount(maxSize, startNewAt); 201 | }; 202 | }; 203 | } 204 | 205 | exports.windowTime = function(timeSpan){ 206 | return function(startNewAt){ 207 | return function(obs){ 208 | return obs.windowTime(timeSpan, startNewAt); 209 | }; 210 | }; 211 | } 212 | 213 | exports.windowToggleImpl = function(obs, openings, closingSelector){ 214 | return obs.windowToggle(openings, closingSelector); 215 | } 216 | 217 | exports.windowWhen = function(obs){ 218 | return function(closing){ 219 | return obs.windowWhen(closing); 220 | }; 221 | } 222 | 223 | /**** Filtering Operators ****/ 224 | 225 | exports.audit = function(obs){ 226 | return function(f){ 227 | return obs.audit(f); 228 | }; 229 | } 230 | 231 | exports.auditTime = function(ms){ 232 | return function(obs){ 233 | return obs.auditTime(ms); 234 | }; 235 | } 236 | 237 | exports.debounce = function (ob) { 238 | return function(f) { 239 | return ob.debounce(f); 240 | }; 241 | } 242 | 243 | exports.debounceTime = function(ms) { 244 | return function(obs){ 245 | return obs.debounceTime(ms); 246 | }; 247 | } 248 | 249 | exports.distinct = function (ob){ 250 | return ob.distinct(); 251 | } 252 | 253 | exports.distinctUntilChanged = function (ob){ 254 | return ob.distinctUntilChanged(); 255 | } 256 | 257 | exports.elementAt = function(obs){ 258 | return function(i){ 259 | return obs.elementAt(i); 260 | }; 261 | } 262 | 263 | exports.filter = function (p){ 264 | return function(ob){ 265 | return ob.filter(p); 266 | }; 267 | } 268 | 269 | exports.first = function(ob){ 270 | return function(p){ 271 | return ob.first(p); 272 | }; 273 | } 274 | 275 | exports.ignoreElements = function(obs){ 276 | return obs.ignoreElements(); 277 | } 278 | 279 | exports.last = function (ob){ 280 | return ob.last(); 281 | } 282 | 283 | exports.sample = function(obs1){ 284 | return function(obs2){ 285 | return obs1.sample(obs2); 286 | }; 287 | } 288 | 289 | exports.sampleTime = function(ms){ 290 | return function(obs){ 291 | return obs.sampleTime(ms); 292 | }; 293 | } 294 | 295 | exports.skip = function(n){ 296 | return function(obs){ 297 | return obs.skip(n); 298 | }; 299 | } 300 | 301 | exports.skipUntil = function(obs1){ 302 | return function(obs2){ 303 | return obs1.skipUntil(obs2); 304 | }; 305 | } 306 | 307 | exports.skipWhile = function (p){ 308 | return function(obs){ 309 | return obs.skipWhile(p); 310 | }; 311 | } 312 | 313 | exports.take = function (n) { 314 | return function(ob) { 315 | return ob.take(n); 316 | }; 317 | } 318 | 319 | exports.takeUntil = function (other) { 320 | return function(ob) { 321 | return ob.takeUntil(other); 322 | }; 323 | } 324 | 325 | exports.takeWhile = function (p){ 326 | return function(obs){ 327 | return obs.takeWhile(p); 328 | }; 329 | } 330 | 331 | exports.throttle = function(obs){ 332 | return function(f){ 333 | return obs.throttle(f); 334 | }; 335 | } 336 | 337 | exports.throttleTime = function(obs){ 338 | return function(ms){ 339 | return obs.throttleTime(ms); 340 | }; 341 | } 342 | 343 | /**** Combination Operators ****/ 344 | 345 | exports.combineLatest = function (f) { 346 | return function(ob1) { 347 | return function(ob2) { 348 | return ob1.combineLatest(ob2, function (x, y) { 349 | return f(x)(y); 350 | }); 351 | }; 352 | }; 353 | } 354 | 355 | exports.concat = function (obs1) { 356 | return function(obs2) { 357 | return obs1.concat(obs1); 358 | }; 359 | } 360 | 361 | exports.concatAll = function (obsobs){ 362 | return obsobs.concatAll(); 363 | } 364 | 365 | exports.exhaust = function (obsobs){ 366 | return obsobs.exhaust(); 367 | } 368 | 369 | exports.merge = function (ob) { 370 | return function(other) { 371 | return ob.merge(other); 372 | }; 373 | } 374 | 375 | exports.mergeAll = function (obsobs){ 376 | return obsobs.mergeAll(); 377 | } 378 | 379 | exports.race = function(arrOfObs){ 380 | return Rx.AsyncSubject.race.apply(this, arrOfObs); 381 | } 382 | 383 | exports.startWith = function (start) { 384 | return function(ob) { 385 | return ob.startWith(start); 386 | }; 387 | } 388 | 389 | 390 | exports.withLatestFrom = function (f) { 391 | return function (ob1) { 392 | return function (ob2) { 393 | return ob1.withLatestFrom(ob2, function(x, y) { 394 | return f(x)(y); 395 | }) 396 | }; 397 | }; 398 | } 399 | 400 | exports.zip = function(arrOfObs){ 401 | return Rx.AsyncSubject.zip.apply(this, arrOfObs); 402 | } 403 | 404 | /**** Error Handling Operators ****/ 405 | 406 | exports.catch = function(obs){ 407 | return function(f){ 408 | return obs.catch(f); 409 | }; 410 | } 411 | 412 | exports.retry = function(nTimes){ 413 | return function(obs){ 414 | return obs.retry(nTimes); 415 | }; 416 | } 417 | 418 | 419 | /**** Utility Operators ****/ 420 | 421 | exports.delay = function (ms){ 422 | return function(ob){ 423 | return ob.delay(ms); 424 | }; 425 | } 426 | 427 | exports.delayWhen = function(obs1){ 428 | return function(f){ 429 | return obs1.delayWhen(f); 430 | }; 431 | } 432 | 433 | exports._materialize = function (ob, Next, Error, Complete) { 434 | return ob.materialize().map(function(x) { 435 | switch (x.kind) { 436 | case 'N': return Next(x.value); 437 | case 'E': return Error(x.error); 438 | case 'C': return Complete; 439 | } 440 | }); 441 | } 442 | 443 | exports.dematerialize = function (ob) { 444 | return ob.map(function(a) { 445 | switch (a.constructor.name) { 446 | case "OnNext": return Rx.Notification.createNext(a.value0); 447 | case "OnError": return Rx.Notification.createError(a.value0); 448 | case "OnComplete": return Rx.Notification.createComplete(); 449 | } 450 | }).dematerialize(); 451 | } 452 | 453 | exports.performEach = function(obs){ 454 | return function(f){ 455 | return function(){ 456 | return obs.do(function(val){ 457 | f(val)(); 458 | }); 459 | }; 460 | }; 461 | } 462 | 463 | exports.toArray = function(obs){ 464 | return obs.toArray(); 465 | } 466 | 467 | /**** Conditional and Boolean Operators ****/ 468 | 469 | exports.defaultIfEmpty = function(obs){ 470 | return function(val){ 471 | return obs.defaultIfEmpty(val); 472 | }; 473 | } 474 | 475 | exports.every = function(obs){ 476 | return function(pred){ 477 | return obs.every(pred); 478 | }; 479 | } 480 | 481 | exports.isEmpty = function(obs){ 482 | return obs.isEmpty(); 483 | } 484 | 485 | /**** Aggregate Operators ****/ 486 | 487 | exports.count = function(obs){ 488 | return obs.count(); 489 | } 490 | 491 | 492 | exports.reduce = function (f){ 493 | return function(seed){ 494 | return function(ob){ 495 | return ob.reduce(function (x, y) { 496 | return f(x)(y); 497 | }, seed); 498 | }; 499 | }; 500 | } 501 | 502 | /**** Helpers ****/ 503 | 504 | exports.unwrap = function (obs) { 505 | return function() { 506 | return obs.map(function(eff) { 507 | return eff(); 508 | }); 509 | }; 510 | } 511 | -------------------------------------------------------------------------------- /src/RxJS/AsyncSubject.purs: -------------------------------------------------------------------------------- 1 | module RxJS.AsyncSubject 2 | ( AsyncSubject(..) 3 | , observeOn 4 | , subscribeOn 5 | , subscribe 6 | , subscribeNext 7 | , just 8 | , asObservable 9 | , buffer 10 | , bufferCount 11 | , bufferToggle 12 | , bufferWhen 13 | , concatMap 14 | , concatMapTo 15 | , every 16 | , exhaustMap 17 | , expand 18 | , groupBy 19 | , mapTo 20 | , mergeMap 21 | , mergeMapTo 22 | , pairwise 23 | , partition 24 | , scan 25 | , switchMap 26 | , switchMapTo 27 | , window 28 | , windowCount 29 | , windowTime 30 | , windowToggle 31 | , windowWhen 32 | , audit 33 | , auditTime 34 | , debounce 35 | , debounceTime 36 | , distinct 37 | , distinctUntilChanged 38 | , elementAt 39 | , filter 40 | , ignoreElements 41 | , last 42 | , sample 43 | , sampleTime 44 | , skip 45 | , skipUntil 46 | , skipWhile 47 | , take 48 | , takeUntil 49 | , takeWhile 50 | , throttle 51 | , throttleTime 52 | , combineLatest 53 | , concat 54 | , concatAll 55 | , exhaust 56 | , merge 57 | , mergeAll 58 | , race 59 | , startWith 60 | , withLatestFrom 61 | , zip 62 | , catch 63 | , retry 64 | , delay 65 | , delayWhen 66 | , dematerialize 67 | , materialize 68 | , performEach 69 | , toArray 70 | , count 71 | ) where 72 | 73 | import RxJS.Scheduler 74 | import Control.Alt (class Alt) 75 | import Control.Alternative (class Alternative) 76 | import Control.Monad.Eff (Eff) 77 | import Control.Monad.Eff.Exception (Error) 78 | import Control.MonadPlus (class MonadPlus) 79 | import Control.MonadZero (class MonadZero) 80 | import Control.Plus (class Plus) 81 | import Data.Function.Uncurried (Fn3, Fn4, runFn3, runFn4) 82 | import Prelude (class Semigroup, class Monad, class Bind, class Applicative, class Apply, class Functor, Unit, id, unit) 83 | import RxJS.Notification (Notification(OnComplete, OnError, OnNext)) 84 | import RxJS.Observable (Observable) 85 | import RxJS.Subscriber (Subscriber) 86 | import RxJS.Subscription (Subscription) 87 | 88 | -- | Please see [RxJS Version 5.* documentation](http://reactivex.io/rxjs/) for 89 | -- | additional details on proper usage of the library. 90 | 91 | 92 | foreign import data AsyncSubject :: Type -> Type 93 | 94 | instance functorAsyncSubject :: Functor AsyncSubject where 95 | map = _map 96 | 97 | instance applyAsyncSubject :: Apply AsyncSubject where 98 | apply = combineLatest id 99 | 100 | instance applicativeAsyncSubject :: Applicative AsyncSubject where 101 | pure = just 102 | 103 | instance bindAsyncSubject :: Bind AsyncSubject where 104 | bind = mergeMap 105 | 106 | instance monadAsyncSubject :: Monad AsyncSubject 107 | 108 | -- | NOTE: The semigroup instance uses `merge` NOT `concat`. 109 | instance semigroupAsyncSubject :: Semigroup (AsyncSubject a) where 110 | append = merge 111 | 112 | instance altAsyncSubject :: Alt AsyncSubject where 113 | alt = merge 114 | 115 | instance plusAsyncSubject :: Plus AsyncSubject where 116 | empty = _empty unit 117 | 118 | instance alternativeAsyncSubject :: Alternative AsyncSubject 119 | 120 | instance monadZeroAsyncSubject :: MonadZero AsyncSubject 121 | 122 | instance monadPlusAsyncSubject :: MonadPlus AsyncSubject 123 | 124 | -- Scheduling 125 | 126 | -- | Makes every `next` call run in the new Scheduler. 127 | foreign import observeOn :: forall a. Scheduler -> AsyncSubject a -> AsyncSubject a 128 | 129 | -- | Makes subscription happen on a given Scheduler. 130 | foreign import subscribeOn :: forall a. Scheduler -> AsyncSubject a -> AsyncSubject a 131 | 132 | -- Subscription 133 | 134 | -- | Subscribing to an AsyncSubject is like calling a function, providing 135 | -- | `next`, `error` and `completed` effects to which the data will be delivered. 136 | foreign import subscribe :: forall a e. Subscriber a -> AsyncSubject a -> Eff (|e) Subscription 137 | 138 | foreign import subscribeObservableTo :: forall a e. Observable a -> AsyncSubject a -> Eff (|e) Subscription 139 | 140 | -- Subscribe to an AsyncSubject, supplying only the `next` function. 141 | foreign import subscribeNext 142 | :: forall a e. (a -> Eff (|e) Unit) 143 | -> AsyncSubject a 144 | -> Eff (|e) Subscription 145 | 146 | 147 | -- Creation Operators 148 | 149 | foreign import _empty :: forall a. Unit -> AsyncSubject a 150 | 151 | -- | Creates an AsyncSubject that emits the value specify, 152 | -- | and then emits a complete notification. An alias for `of`. 153 | foreign import just :: forall a. a -> AsyncSubject a 154 | 155 | -- AsyncSubject Operators 156 | 157 | -- | Create an Observable from a AsyncSubject 158 | foreign import asObservable :: forall a. AsyncSubject a -> Observable a 159 | 160 | 161 | -- Transformation Operators 162 | 163 | -- | Collects values from the first AsyncSubject into an Array, and emits that array only when 164 | -- | second AsyncSubject emits. 165 | foreign import buffer :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject (Array a) 166 | 167 | -- | Collects values from the past as an array, emits that array when 168 | -- | its size (arg1) reaches the specified buffer size, and starts a new buffer. 169 | -- | The new buffer starts with nth (arg2) element of the AsyncSubject counting 170 | -- | from the beginning of the *last* buffer. 171 | foreign import bufferCount :: forall a. Int -> Int -> AsyncSubject a -> AsyncSubject (Array a) 172 | 173 | -- | Collects values from the past as an array, and emits those arrays 174 | -- | periodically in time. The first argument is how long to fill the buffer. 175 | -- | The second argument is specifies when to open the next buffer following an 176 | -- | emission. The third argument is the maximum size of any buffer. 177 | bufferTime :: forall a. Int -> Int -> Int -> (AsyncSubject a) -> (AsyncSubject (Array a)) 178 | bufferTime = runFn4 bufferTimeImpl 179 | 180 | foreign import bufferTimeImpl :: forall a. Fn4 Int Int Int (AsyncSubject a) (AsyncSubject (Array a)) 181 | 182 | -- | Collects values from the source AsyncSubject (arg1) as an array. Starts collecting only when 183 | -- | the opening (arg2) AsyncSubject emits, and calls the closingSelector function (arg3) to get an AsyncSubject 184 | -- | that decides when to close the buffer. Another buffer opens when the 185 | -- | opening AsyncSubject emits its next value. 186 | bufferToggle 187 | :: forall a b c. (AsyncSubject a) 188 | -> (AsyncSubject b) 189 | -> (b -> AsyncSubject c) 190 | -> (AsyncSubject (Array a)) 191 | bufferToggle = runFn3 bufferToggleImpl 192 | 193 | 194 | foreign import bufferToggleImpl 195 | :: forall a b c. Fn3 (AsyncSubject a) (AsyncSubject b) (b -> AsyncSubject c) (AsyncSubject (Array a)) 196 | 197 | -- | Collects values from the past as an array. When it starts collecting values, 198 | -- | it calls a function that returns an AsyncSubject that emits to close the 199 | -- | buffer and restart collecting. 200 | foreign import bufferWhen :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject (Array a) 201 | 202 | -- | Equivalent to mergeMap (a.k.a, `>>=`) EXCEPT that, unlike mergeMap, 203 | -- | the next bind will not run until the AsyncSubject generated by the projection function (arg2) 204 | -- | completes. That is, composition is sequential, not concurrent. 205 | -- | Warning: if source values arrive endlessly and faster than their corresponding 206 | -- | inner AsyncSubjects can complete, it will result in memory issues as inner 207 | -- | AsyncSubjects amass in an unbounded buffer waiting for their turn to be subscribed to. 208 | foreign import concatMap :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject b 209 | 210 | -- | The type signature explains it best. Warning: Like `concatMap`, composition is sequential. 211 | foreign import concatMapTo 212 | :: forall a b c. AsyncSubject a -> AsyncSubject b -> (a -> b -> AsyncSubject c) -> AsyncSubject c 213 | 214 | -- | It's Like concatMap (a.k.a, `>>=`) EXCEPT that it ignores every new projected 215 | -- | AsyncSubject if the previous projected AsyncSubject has not yet completed. 216 | foreign import exhaustMap :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject b 217 | 218 | -- | It's similar to mergeMap, but applies the projection function to every source 219 | -- | value as well as every output value. It's recursive. 220 | foreign import expand :: forall a. AsyncSubject a -> (a -> AsyncSubject a) -> AsyncSubject a 221 | 222 | -- | Groups the items emitted by an AsyncSubject (arg2) according to the value 223 | -- | returned by the grouping function (arg1). Each group becomes its own 224 | -- | AsyncSubject. 225 | foreign import groupBy :: forall a b. (a -> b) -> AsyncSubject a -> AsyncSubject (AsyncSubject a) 226 | 227 | foreign import _map :: forall a b. (a -> b) -> AsyncSubject a -> AsyncSubject b 228 | 229 | -- | Emits the given constant value on the output AsyncSubject every time 230 | -- | the source AsyncSubject emits a value. 231 | foreign import mapTo :: forall a b. b -> AsyncSubject a -> AsyncSubject b 232 | 233 | -- | Maps each value to an AsyncSubject, then flattens all of these AsyncSubjects 234 | -- | using mergeAll. It's just monadic `bind`. 235 | foreign import mergeMap :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject b 236 | 237 | -- | Maps each value of the AsyncSubject (arg1) to the same inner AsyncSubject (arg2), 238 | -- | then flattens the result. 239 | foreign import mergeMapTo :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject b 240 | 241 | -- | Puts the current value and previous value together as an array, and emits that. 242 | foreign import pairwise :: forall a. AsyncSubject a -> AsyncSubject (Array a) 243 | 244 | -- | Given a predicate function (arg1), and an AsyncSubject (arg2), it outputs a 245 | -- | two element array of partitioned values 246 | -- | (i.e., [ AsyncSubject valuesThatPassPredicate, AsyncSubject valuesThatFailPredicate ]). 247 | foreign import partition :: forall a. (a -> Boolean) -> AsyncSubject a -> Array (AsyncSubject a) 248 | 249 | -- | Given an accumulator function (arg1), an initial value (arg2), and 250 | -- | a source AsyncSubject (arg3), it returns an AsyncSubject that emits the current 251 | -- | accumlation whenever the source emits a value. 252 | foreign import scan :: forall a b. (a -> b -> b) -> b -> AsyncSubject a -> AsyncSubject b 253 | 254 | -- | Projects each source value to an AsyncSubject which is merged in the output 255 | -- | AsyncSubject, emitting values only from the most recently projected AsyncSubject. 256 | foreign import switchMap :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject b 257 | 258 | -- | It's like switchMap, but maps each value to the same inner AsyncSubject. 259 | foreign import switchMapTo :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject b 260 | 261 | -- | It's like buffer, but emits a nested AsyncSubject instead of an array. 262 | foreign import window :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject (AsyncSubject a) 263 | 264 | -- | It's like bufferCount, but emits a nested AsyncSubject instead of an array. 265 | foreign import windowCount :: forall a. Int -> Int -> AsyncSubject a -> AsyncSubject (AsyncSubject a) 266 | 267 | -- | It's like bufferTime, but emits a nested AsyncSubject instead of an array, 268 | -- | and it doesn't take a maximum size parameter. arg1 is how long to 269 | -- | buffer items into a new AsyncSubject, arg2 is the when the next buffer should begin, 270 | -- | and arg3 is the source AsyncSubject. 271 | foreign import windowTime :: forall a. Int -> Int -> AsyncSubject a -> AsyncSubject (AsyncSubject a) 272 | 273 | -- | It's like bufferToggle, but emits a nested AsyncSubject instead of an array. 274 | windowToggle 275 | :: forall a b c. (AsyncSubject a) 276 | -> (AsyncSubject b) 277 | -> (b -> AsyncSubject c) 278 | -> (AsyncSubject (Array a)) 279 | windowToggle = runFn3 windowToggleImpl 280 | 281 | foreign import windowToggleImpl 282 | :: forall a b c. Fn3 (AsyncSubject a) (AsyncSubject b) (b -> AsyncSubject c) (AsyncSubject (Array a)) 283 | 284 | -- | It's like bufferWhen, but emits a nested AsyncSubject instead of an array. 285 | foreign import windowWhen :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject (AsyncSubject a) 286 | 287 | -- Filtering Operators 288 | 289 | -- | It's like auditTime, but the silencing duration is determined by a second AsyncSubject. 290 | foreign import audit :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject a 291 | 292 | -- | Ignores source values for duration milliseconds, 293 | -- | then emits the most recent value from the source AsyncSubject, then repeats this process. 294 | foreign import auditTime :: forall a. Int -> AsyncSubject a -> AsyncSubject a 295 | 296 | -- | It's like debounceTime, but the time span of emission silence is determined 297 | -- | by a second AsyncSubject. Allows for a variable debounce rate. 298 | foreign import debounce :: forall a. AsyncSubject a -> (a -> AsyncSubject Int) -> AsyncSubject a 299 | 300 | -- | It's like delay, but passes only the most recent value from each burst of emissions. 301 | foreign import debounceTime :: forall a. Int -> AsyncSubject a -> AsyncSubject a 302 | 303 | -- | Returns an AsyncSubject that emits all items emitted by the source AsyncSubject 304 | -- | that are distinct by comparison from previous items. 305 | foreign import distinct :: forall a. AsyncSubject a -> AsyncSubject a 306 | 307 | -- | Returns an AsyncSubject that emits all items emitted by the source AsyncSubject 308 | -- | that are distinct by comparison from the previous item. 309 | foreign import distinctUntilChanged :: forall a. AsyncSubject a -> AsyncSubject a 310 | 311 | -- | Emits the single value at the specified index in a sequence of emissions 312 | -- | from the source AsyncSubject. 313 | foreign import elementAt :: forall a. AsyncSubject a -> Int -> AsyncSubject a 314 | 315 | -- | Filter items emitted by the source AsyncSubject by only emitting those that 316 | -- | satisfy a specified predicate. 317 | foreign import filter :: forall a. (a -> Boolean) -> AsyncSubject a -> AsyncSubject a 318 | 319 | -- | Ignores all items emitted by the source AsyncSubject and only passes calls of complete or error. 320 | foreign import ignoreElements :: forall a. AsyncSubject a -> AsyncSubject a 321 | 322 | -- | Returns an AsyncSubject that emits only the last item emitted by the source AsyncSubject. 323 | foreign import last :: forall a. AsyncSubject a -> AsyncSubject a 324 | 325 | -- | It's like sampleTime, but samples whenever the notifier AsyncSubject emits something. 326 | foreign import sample :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject a 327 | 328 | -- | Periodically looks at the source AsyncSubject and emits whichever 329 | -- | value it has most recently emitted since the previous sampling, unless the source has not emitted anything since the previous sampling. 330 | foreign import sampleTime :: forall a. Int -> AsyncSubject a -> AsyncSubject a 331 | 332 | -- | Returns an AsyncSubject that skips n items emitted by an AsyncSubject. 333 | foreign import skip :: forall a. Int -> AsyncSubject a -> AsyncSubject a 334 | 335 | -- | Returns an AsyncSubject that skips items emitted by the source AsyncSubject until a second AsyncSubject emits an item. 336 | foreign import skipUntil :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject a 337 | 338 | -- | Returns an AsyncSubject that skips all items emitted 339 | -- | by the source AsyncSubject as long as a specified condition holds true, 340 | -- | but emits all further source items as soon as the condition becomes false. 341 | foreign import skipWhile :: forall a. (a -> Boolean) -> AsyncSubject a -> AsyncSubject a 342 | 343 | -- | Emits only the first n values emitted by the source AsyncSubject. 344 | foreign import take :: forall a. Int -> AsyncSubject a -> AsyncSubject a 345 | 346 | -- | Lets values pass until a second AsyncSubject emits something. Then, it completes. 347 | foreign import takeUntil :: forall a b. AsyncSubject a -> AsyncSubject b -> AsyncSubject a 348 | 349 | -- | Emits values emitted by the source AsyncSubject so long as each value satisfies 350 | -- | the given predicate, and then completes as soon as this predicate is not satisfied. 351 | foreign import takeWhile :: forall a. (a -> Boolean) -> AsyncSubject a -> AsyncSubject a 352 | 353 | -- | It's like throttleTime, but the silencing duration is determined by a second AsyncSubject. 354 | foreign import throttle :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject a 355 | 356 | -- | Emits a value from the source AsyncSubject, then ignores subsequent source values 357 | -- | for duration milliseconds, then repeats this process. 358 | foreign import throttleTime :: forall a. Int -> AsyncSubject a -> AsyncSubject a 359 | 360 | 361 | -- Combination Operators 362 | 363 | -- | An AsyncSubject of projected values from the most recent values from each input AsyncSubject. 364 | foreign import combineLatest 365 | :: forall a b c. (a -> b -> c) -> AsyncSubject a -> AsyncSubject b -> AsyncSubject c 366 | 367 | -- | Concatenates two AsyncSubjects together by sequentially emitting their values, one AsyncSubject after the other. 368 | foreign import concat :: forall a. AsyncSubject a -> AsyncSubject a -> AsyncSubject a 369 | 370 | -- | Converts a higher-order AsyncSubject into a first-order AsyncSubject by concatenating the inner AsyncSubjects in order. 371 | foreign import concatAll :: forall a. AsyncSubject (AsyncSubject a) -> AsyncSubject a 372 | 373 | -- | Flattens an AsyncSubject-of-AsyncSubjects by dropping the next inner AsyncSubjects 374 | -- | while the current inner is still executing. 375 | foreign import exhaust :: forall a. AsyncSubject (AsyncSubject a) -> AsyncSubject a 376 | 377 | -- | Creates an output AsyncSubject which concurrently emits all values from each input AsyncSubject. 378 | foreign import merge :: forall a. AsyncSubject a -> AsyncSubject a -> AsyncSubject a 379 | 380 | -- | Converts a higher-order AsyncSubject into a first-order AsyncSubject 381 | -- | which concurrently delivers all values that are emitted on the inner AsyncSubjects. 382 | foreign import mergeAll :: forall a. AsyncSubject (AsyncSubject a) -> AsyncSubject a 383 | 384 | -- | Returns an AsyncSubject that mirrors the first source AsyncSubject to emit an 385 | -- | item from the array of AsyncSubjects. 386 | foreign import race :: forall a. Array (AsyncSubject a) -> AsyncSubject a 387 | 388 | -- | Returns an AsyncSubject that emits the items in the given Array before 389 | -- | it begins to emit items emitted by the source AsyncSubject. 390 | foreign import startWith :: forall a. Array a -> AsyncSubject a -> AsyncSubject a 391 | 392 | -- | Combines each value from the source AsyncSubjects using a project function to 393 | -- | determine the value to be emitted on the output AsyncSubject. 394 | foreign import withLatestFrom 395 | :: forall a b c. (a -> b -> c) -> AsyncSubject a -> AsyncSubject b -> AsyncSubject c 396 | 397 | -- | Waits for each AsyncSubject to emit a value. Once this occurs, all values 398 | -- | with the corresponding index will be emitted. This will continue until at 399 | -- | least one inner AsyncSubject completes. 400 | foreign import zip :: forall a. Array (AsyncSubject a) -> AsyncSubject (Array a) 401 | 402 | -- Error Handling Operators 403 | 404 | foreign import catch :: forall a. (AsyncSubject a) -> (Error -> AsyncSubject a) -> (AsyncSubject a) 405 | 406 | -- | If the source AsyncSubject calls error, this method will resubscribe to the 407 | -- | source AsyncSubject n times rather than propagating the error call. 408 | foreign import retry :: forall a. Int -> AsyncSubject a -> AsyncSubject a 409 | 410 | -- Utility Operators 411 | 412 | -- | Time shifts each item by some specified amount of milliseconds. 413 | foreign import delay :: forall a. Int -> AsyncSubject a -> AsyncSubject a 414 | 415 | -- | Delays the emission of items from the source AsyncSubject by a given time 416 | -- | span determined by the emissions of another AsyncSubject. 417 | foreign import delayWhen :: forall a b. AsyncSubject a -> (a -> AsyncSubject b) -> AsyncSubject a 418 | 419 | foreign import dematerialize :: forall a. AsyncSubject (Notification a) -> AsyncSubject a 420 | 421 | foreign import _materialize 422 | :: forall a. 423 | Fn4 424 | (AsyncSubject a) 425 | (a -> Notification a) 426 | (Error -> Notification a) 427 | (Notification a) 428 | (AsyncSubject (Notification a)) 429 | 430 | materialize :: forall a. AsyncSubject a -> AsyncSubject (Notification a) 431 | materialize ob = runFn4 _materialize ob OnNext OnError OnComplete 432 | -- | Performs the effect on each value of the AsyncSubject. An alias for `do`. 433 | -- | Useful for testing (transparently performing an effect outside of a subscription). 434 | 435 | foreign import performEach :: forall a e. AsyncSubject a -> (a -> Eff (|e) Unit) -> Eff (|e) (AsyncSubject a) 436 | 437 | foreign import toArray :: forall a. AsyncSubject a -> AsyncSubject (Array a) 438 | 439 | -- | Returns an AsyncSubject that emits the items emitted by the source AsyncSubject or a specified default item 440 | -- | if the source AsyncSubject is empty. 441 | -- | 442 | -- | ![marble diagram](http://reactivex.io/documentation/operators/images/defaultIfEmpty.c.png) 443 | -- | 444 | -- | takes a defaultValue which is the item to emit if the source AsyncSubject emits no items. 445 | -- | 446 | -- | returns an AsyncSubject that emits either the specified default item if the source AsyncSubject emits no 447 | -- | items, or the items emitted by the source AsyncSubject 448 | foreign import defaultIfEmpty :: forall a. AsyncSubject a -> a -> AsyncSubject a 449 | 450 | -- | Determines whether all elements of an AsyncSubject satisfy a condition. 451 | -- | Returns an AsyncSubject containing a single element determining whether all 452 | -- | elements in the source AsyncSubject pass the test in the specified predicate. 453 | foreign import every :: forall a. AsyncSubject a -> (a -> Boolean) -> AsyncSubject Boolean 454 | 455 | -- | Tests whether this `AsyncSubject` emits no elements. 456 | -- | 457 | -- | returns an AsyncSubject emitting one single Boolean, which is `true` if this `AsyncSubject` 458 | -- | emits no elements, and `false` otherwise. 459 | foreign import isEmpty :: forall a. AsyncSubject a -> AsyncSubject Boolean 460 | 461 | -- | Returns an AsyncSubject that emits only the first item emitted by the source 462 | -- | AsyncSubject that satisfies the given predicate. 463 | foreign import first :: forall a. AsyncSubject a -> (a -> Boolean) -> AsyncSubject a 464 | 465 | -- Aggregate Operators 466 | 467 | -- | Counts the number of emissions on the source and emits that number when the source completes. 468 | foreign import count :: forall a. AsyncSubject a -> AsyncSubject Int 469 | 470 | -- | Applies an accumulator function over the source, and returns the accumulated 471 | -- | result when the source completes, given a seed value. 472 | foreign import reduce :: forall a b. (a -> b -> b) -> b -> AsyncSubject a -> AsyncSubject b 473 | 474 | -- Helper Functions 475 | 476 | -- | Run a source's effects 477 | foreign import unwrap :: forall a e. AsyncSubject (Eff e a) -> Eff e (AsyncSubject a) 478 | -------------------------------------------------------------------------------- /src/RxJS/BehaviorSubject.js: -------------------------------------------------------------------------------- 1 | /* global exports */ 2 | "use strict"; 3 | 4 | // module RxJS.BehaviorSubject 5 | 6 | var Rx = require('rxjs'); 7 | 8 | /**** Scheduling ****/ 9 | 10 | exports.observeOn = function(s){ 11 | return function(obs){ 12 | return obs.observeOn(s); 13 | }; 14 | } 15 | 16 | exports.subscribeOn = function(s){ 17 | return function(obs){ 18 | return obs.subscribeOn(s); 19 | }; 20 | } 21 | 22 | /**** Subscription ****/ 23 | 24 | exports.subscribe = function(sub){ 25 | return function(obs) { 26 | return function(){ 27 | return obs.subscribe( 28 | function(val){ sub.next(val)();}, 29 | function(err){ sub.error(err)();}, 30 | function(){sub.complete()();} 31 | ); 32 | }; 33 | }; 34 | } 35 | 36 | exports.subscribeObservableTo = function(obs){ 37 | return function(sub){ 38 | return function(){ 39 | return obs.subscribe(sub); 40 | }; 41 | }; 42 | } 43 | 44 | exports.subscribeNext = function (eff){ 45 | return function(obs){ 46 | return function(){ 47 | obs.subscribe( 48 | function(val){return eff(val)();} 49 | ); 50 | }; 51 | }; 52 | } 53 | 54 | /**** Creation Operator ****/ 55 | 56 | 57 | exports.just = function(val){ 58 | return new Rx.BehaviorSubject(val); 59 | } 60 | 61 | /**** BehaviorSubject Operators ****/ 62 | 63 | exports.asObservable = function(bs){ 64 | return bs.asObservable(); 65 | } 66 | 67 | exports.getValue = function(bs){ 68 | return function() { 69 | return bs.getValue(); 70 | }; 71 | } 72 | 73 | exports.next = function(val){ 74 | return function(bs){ 75 | return function(){ 76 | bs.next(val); 77 | }; 78 | }; 79 | } 80 | 81 | /**** Transformation Operators ****/ 82 | 83 | exports.buffer = function(obs1){ 84 | return function(obs2){ 85 | return obs1.buffer(obs2); 86 | }; 87 | } 88 | 89 | exports.bufferCount = function(maxSize){ 90 | return function(startNewAt){ 91 | return function(obs){ 92 | return obs.bufferCount(maxSize, startNewAt); 93 | }; 94 | }; 95 | } 96 | 97 | exports.bufferTimeImpl = function(timespan, creationInterval, maxSize, obs){ 98 | return obs.bufferTime(timespan, creationInterval, maxSize); 99 | } 100 | 101 | exports.bufferToggleImpl = function(obs, openings, closingSelector){ 102 | return obs.bufferToggle(openings, closingSelector); 103 | } 104 | 105 | exports.bufferWhen = function(obs){ 106 | return function(closing){ 107 | return obs.bufferWhen(closing); 108 | }; 109 | } 110 | 111 | exports.concatMap = function(obs){ 112 | return function(f){ 113 | return obs.concatMap(f); 114 | }; 115 | } 116 | 117 | exports.concatMapTo = function(obs1){ 118 | return function(obs2){ 119 | return function(f){ 120 | return obs1.concatMapTo(obs2, function(a, b){ 121 | return f(a)(b); 122 | }); 123 | }; 124 | }; 125 | } 126 | 127 | exports.exhaustMap = function(obs){ 128 | return function(f){ 129 | return obs.exhaustMap(f); 130 | }; 131 | } 132 | 133 | exports.expand = function(obs){ 134 | return function(f){ 135 | return obs.expand(f); 136 | }; 137 | } 138 | 139 | exports.groupBy = function(f){ 140 | return function(obs){ 141 | return obs.groupBy(f); 142 | }; 143 | } 144 | 145 | exports._map = function(f){ 146 | return function(obs){ 147 | return obs.map(f); 148 | }; 149 | } 150 | 151 | exports.mapTo = function(val){ 152 | return function(obs1){ 153 | return obs1.mapTo(val); 154 | }; 155 | } 156 | 157 | exports.mergeMap = function(obs){ 158 | return function(f){ 159 | return obs.mergeMap(f); 160 | }; 161 | } 162 | 163 | 164 | exports.mergeMapTo = function(obs1){ 165 | return function(obs2){ 166 | return obs1.mergeMapTo(obs2); 167 | }; 168 | } 169 | 170 | exports.pairwise = function(obs){ 171 | return obs.pairwise(); 172 | } 173 | 174 | exports.partition = function(pred){ 175 | return function(obs){ 176 | return obs.partition(pred); 177 | }; 178 | } 179 | 180 | exports.scan = function scan(f) { 181 | return function(seed) { 182 | return function(ob) { 183 | return ob.scan(function(acc, value) { 184 | return f(value)(acc); 185 | }, seed); 186 | }; 187 | }; 188 | } 189 | 190 | exports.switchMap = function(obs){ 191 | return function(f){ 192 | return obs.switchMap(f); 193 | }; 194 | } 195 | 196 | exports.switchMapTo = function(obs1){ 197 | return function(obs2){ 198 | return obs1.switchMapTo(obs2); 199 | }; 200 | } 201 | 202 | exports.window = function(obs1){ 203 | return function(obs2){ 204 | return obs1.window(obs2); 205 | }; 206 | } 207 | 208 | exports.windowCount = function(maxSize){ 209 | return function(startNewAt){ 210 | return function(obs){ 211 | return obs.windowCount(maxSize, startNewAt); 212 | }; 213 | }; 214 | } 215 | 216 | exports.windowTime = function(timeSpan){ 217 | return function(startNewAt){ 218 | return function(obs){ 219 | return obs.windowTime(timeSpan, startNewAt); 220 | }; 221 | }; 222 | } 223 | 224 | exports.windowToggleImpl = function(obs, openings, closingSelector){ 225 | return obs.windowToggle(openings, closingSelector); 226 | } 227 | 228 | exports.windowWhen = function(obs){ 229 | return function(closing){ 230 | return obs.windowWhen(closing); 231 | }; 232 | } 233 | 234 | /**** Filtering Operators ****/ 235 | 236 | exports.audit = function(obs){ 237 | return function(f){ 238 | return obs.audit(f); 239 | }; 240 | } 241 | 242 | exports.auditTime = function(ms){ 243 | return function(obs){ 244 | return obs.auditTime(ms); 245 | }; 246 | } 247 | 248 | exports.debounce = function (ob) { 249 | return function(f) { 250 | return ob.debounce(f); 251 | }; 252 | } 253 | 254 | exports.debounceTime = function(ms) { 255 | return function(obs){ 256 | return obs.debounceTime(ms); 257 | }; 258 | } 259 | 260 | exports.distinct = function (ob){ 261 | return ob.distinct(); 262 | } 263 | 264 | exports.distinctUntilChanged = function (ob){ 265 | return ob.distinctUntilChanged(); 266 | } 267 | 268 | exports.elementAt = function(obs){ 269 | return function(i){ 270 | return obs.elementAt(i); 271 | }; 272 | } 273 | 274 | exports.filter = function (p){ 275 | return function(ob){ 276 | return ob.filter(p); 277 | }; 278 | } 279 | 280 | exports.first = function (p){ 281 | return function(ob){ 282 | return ob.first(p); 283 | }; 284 | } 285 | 286 | exports.ignoreElements = function(obs){ 287 | return obs.ignoreElements(); 288 | } 289 | 290 | exports.last = function (ob){ 291 | return ob.last(); 292 | } 293 | 294 | exports.sample = function(obs1){ 295 | return function(obs2){ 296 | return obs1.sample(obs2); 297 | }; 298 | } 299 | 300 | exports.sampleTime = function(ms){ 301 | return function(obs){ 302 | return obs.sampleTime(ms); 303 | }; 304 | } 305 | 306 | exports.skip = function(n){ 307 | return function(obs){ 308 | return obs.skip(n); 309 | }; 310 | } 311 | 312 | exports.skipUntil = function(obs1){ 313 | return function(obs2){ 314 | return obs1.skipUntil(obs2); 315 | }; 316 | } 317 | 318 | exports.skipWhile = function (p){ 319 | return function(obs){ 320 | return obs.skipWhile(p); 321 | }; 322 | } 323 | 324 | exports.take = function (n) { 325 | return function(ob) { 326 | return ob.take(n); 327 | }; 328 | } 329 | 330 | exports.takeUntil = function (other) { 331 | return function(ob) { 332 | return ob.takeUntil(other); 333 | }; 334 | } 335 | 336 | exports.takeWhile = function (p){ 337 | return function(obs){ 338 | return obs.takeWhile(p); 339 | }; 340 | } 341 | 342 | exports.throttle = function(obs){ 343 | return function(f){ 344 | return obs.throttle(f); 345 | }; 346 | } 347 | 348 | exports.throttleTime = function(obs){ 349 | return function(ms){ 350 | return obs.throttleTime(ms); 351 | }; 352 | } 353 | 354 | /**** Combination Operators ****/ 355 | 356 | exports.combineLatest = function (f) { 357 | return function(ob1) { 358 | return function(ob2) { 359 | return ob1.combineLatest(ob2, function (x, y) { 360 | return f(x)(y); 361 | }); 362 | }; 363 | }; 364 | } 365 | 366 | exports.concat = function (obs1) { 367 | return function(obs2) { 368 | return obs1.concat(obs1); 369 | }; 370 | } 371 | 372 | exports.concatAll = function (obsobs){ 373 | return obsobs.concatAll(); 374 | } 375 | 376 | exports.exhaust = function (obsobs){ 377 | return obsobs.exhaust(); 378 | } 379 | 380 | exports.merge = function (ob) { 381 | return function(other) { 382 | return ob.merge(other); 383 | }; 384 | } 385 | 386 | exports.mergeAll = function (obsobs){ 387 | return obsobs.mergeAll(); 388 | } 389 | 390 | exports.race = function(arrOfObs){ 391 | return Rx.BehaviorSubject.race.apply(this, arrOfObs); 392 | } 393 | 394 | exports.startWith = function (start) { 395 | return function(ob) { 396 | return ob.startWith(start); 397 | }; 398 | } 399 | 400 | 401 | exports.withLatestFrom = function (f) { 402 | return function (ob1) { 403 | return function (ob2) { 404 | return ob1.withLatestFrom(ob2, function(x, y) { 405 | return f(x)(y); 406 | }) 407 | }; 408 | }; 409 | } 410 | 411 | exports.zip = function(arrOfObs){ 412 | return Rx.BehaviorSubject.zip.apply(this, arrOfObs); 413 | } 414 | 415 | /**** Error Handling Operators ****/ 416 | 417 | exports.catch = function(obs){ 418 | return function(f){ 419 | return obs.catch(f); 420 | }; 421 | } 422 | 423 | exports.retry = function(nTimes){ 424 | return function(obs){ 425 | return obs.retry(nTimes); 426 | }; 427 | } 428 | 429 | 430 | /**** Utility Operators ****/ 431 | 432 | exports.delay = function (ms){ 433 | return function(ob){ 434 | return ob.delay(ms); 435 | }; 436 | } 437 | 438 | exports.delayWhen = function(obs1){ 439 | return function(f){ 440 | return obs1.delayWhen(f); 441 | }; 442 | } 443 | 444 | exports._materialize = function (ob, Next, Error, Complete) { 445 | return ob.materialize().map(function(x) { 446 | switch (x.kind) { 447 | case 'N': return Next(x.value); 448 | case 'E': return Error(x.error); 449 | case 'C': return Complete; 450 | } 451 | }); 452 | } 453 | 454 | exports.dematerialize = function (ob) { 455 | return ob.map(function(a) { 456 | switch (a.constructor.name) { 457 | case "OnNext": return Rx.Notification.createNext(a.value0); 458 | case "OnError": return Rx.Notification.createError(a.value0); 459 | case "OnComplete": return Rx.Notification.createComplete(); 460 | } 461 | }).dematerialize(); 462 | } 463 | 464 | exports.performEach = function(obs){ 465 | return function(f){ 466 | return function(){ 467 | return obs.do(function(val){ 468 | f(val)(); 469 | }); 470 | }; 471 | }; 472 | } 473 | 474 | 475 | exports.toArray = function(obs){ 476 | return obs.toArray(); 477 | } 478 | 479 | /**** Conditional and Boolean Operators ****/ 480 | 481 | exports.defaultIfEmpty = function(obs){ 482 | return function(val){ 483 | return obs.defaultIfEmpty(val); 484 | }; 485 | } 486 | 487 | exports.every = function(pred){ 488 | return function(obs){ 489 | return obs.every(pred); 490 | }; 491 | } 492 | 493 | exports.isEmpty = function(obs){ 494 | return obs.isEmpty(); 495 | } 496 | 497 | /**** Aggregate Operators ****/ 498 | 499 | exports.count = function(obs){ 500 | return obs.count(); 501 | } 502 | 503 | 504 | exports.reduce = function (f){ 505 | return function(seed){ 506 | return function(ob){ 507 | return ob.reduce(function (x, y) { 508 | return f(x)(y); 509 | }, seed); 510 | }; 511 | }; 512 | } 513 | 514 | /**** Helpers ****/ 515 | 516 | exports.unwrap = function (obs) { 517 | return function() { 518 | return obs.map(function(eff) { 519 | return eff(); 520 | }); 521 | }; 522 | } 523 | -------------------------------------------------------------------------------- /src/RxJS/BehaviorSubject.purs: -------------------------------------------------------------------------------- 1 | module RxJS.BehaviorSubject 2 | ( BehaviorSubject() 3 | , observeOn 4 | , subscribeOn 5 | , subscribe 6 | , subscribeNext 7 | , just 8 | , next 9 | , send 10 | , asObservable 11 | , getValue 12 | , buffer 13 | , bufferCount 14 | , bufferToggle 15 | , bufferWhen 16 | , concatMap 17 | , concatMapTo 18 | , exhaustMap 19 | , expand 20 | , groupBy 21 | , mapTo 22 | , mergeMap 23 | , mergeMapTo 24 | , pairwise 25 | , partition 26 | , scan 27 | , switchMap 28 | , switchMapTo 29 | , window 30 | , windowCount 31 | , windowTime 32 | , windowToggle 33 | , windowWhen 34 | , audit 35 | , auditTime 36 | , debounce 37 | , debounceTime 38 | , distinct 39 | , distinctUntilChanged 40 | , elementAt 41 | , filter 42 | , ignoreElements 43 | , last 44 | , sample 45 | , sampleTime 46 | , skip 47 | , skipUntil 48 | , skipWhile 49 | , take 50 | , takeUntil 51 | , takeWhile 52 | , throttle 53 | , throttleTime 54 | , combineLatest 55 | , concat 56 | , concatAll 57 | , exhaust 58 | , merge 59 | , mergeAll 60 | , race 61 | , startWith 62 | , withLatestFrom 63 | , zip 64 | , catch 65 | , retry 66 | , delay 67 | , delayWhen 68 | , dematerialize 69 | , materialize 70 | , performEach 71 | , toArray 72 | , count 73 | ) where 74 | 75 | import RxJS.Scheduler (Scheduler) 76 | import Control.Alt (class Alt) 77 | import Control.Monad.Eff (Eff) 78 | import Control.Monad.Eff.Exception (Error) 79 | import Data.Function.Uncurried (Fn3, Fn4, runFn3, runFn4) 80 | import Prelude (class Semigroup, class Monad, class Bind, class Applicative, class Apply, class Functor, Unit, id) 81 | import RxJS.Notification (Notification(OnComplete, OnError, OnNext)) 82 | import RxJS.Observable (Observable) 83 | import RxJS.Subscriber (Subscriber) 84 | import RxJS.Subscription (Subscription) 85 | 86 | -- | Please see [RxJS Version 5.* documentation](http://reactivex.io/rxjs/) for 87 | -- | additional details on proper usage of the library. 88 | 89 | foreign import data BehaviorSubject :: Type -> Type 90 | 91 | instance functorBehaviorSubject :: Functor BehaviorSubject where 92 | map = _map 93 | 94 | instance applyBehaviorSubject :: Apply BehaviorSubject where 95 | apply = combineLatest id 96 | 97 | instance applicativeBehaviorSubject :: Applicative BehaviorSubject where 98 | pure = just 99 | 100 | instance bindBehaviorSubject :: Bind BehaviorSubject where 101 | bind = mergeMap 102 | 103 | instance monadBehaviorSubject :: Monad BehaviorSubject 104 | 105 | -- | NOTE: The semigroup instance uses `merge` NOT `concat`. 106 | instance semigroupBehaviorSubject :: Semigroup (BehaviorSubject a) where 107 | append = merge 108 | 109 | instance altBehaviorSubject :: Alt BehaviorSubject where 110 | alt = merge 111 | 112 | -- Scheduling 113 | 114 | -- | Makes every `next` call run in the new Scheduler. 115 | foreign import observeOn :: forall a. Scheduler -> BehaviorSubject a -> BehaviorSubject a 116 | 117 | -- | Makes subscription happen on a given Scheduler. 118 | foreign import subscribeOn :: forall a. Scheduler -> BehaviorSubject a -> BehaviorSubject a 119 | 120 | 121 | -- Subscription 122 | 123 | -- | Subscribing to an BehaviorSubject is like calling a function, providing 124 | -- | `next`, `error` and `completed` effects to which the data will be delivered. 125 | foreign import subscribe :: forall a e. Subscriber a -> BehaviorSubject a -> Eff (|e) Subscription 126 | 127 | foreign import subscribeObservableTo :: forall a e. Observable a -> BehaviorSubject a -> Eff (|e) Subscription 128 | 129 | -- Subscribe to an BehaviorSubject, supplying only the `next` function. 130 | foreign import subscribeNext 131 | :: forall a e. (a -> Eff (|e) Unit) 132 | -> BehaviorSubject a 133 | -> Eff (|e) Subscription 134 | 135 | 136 | -- Creation Operator 137 | 138 | -- | Creates an BehaviorSubject that emits the value specify, 139 | -- | and then emits a complete notification. An alias for `of`. 140 | foreign import just :: forall a. a -> BehaviorSubject a 141 | 142 | -- BehaviorSubject Operators 143 | 144 | -- | Send a new value to a BehaviorSubject 145 | foreign import next :: forall a e. a -> BehaviorSubject a -> Eff e Unit 146 | 147 | -- | An alias for next 148 | send :: forall a e. a -> BehaviorSubject a -> Eff e Unit 149 | send = next 150 | 151 | -- | Create an Observable from a BehaviorSubject 152 | foreign import asObservable :: forall a. BehaviorSubject a -> Observable a 153 | 154 | -- | Obtain the current value of a BehaviorSubject 155 | foreign import getValue :: forall a e. BehaviorSubject a -> Eff e a 156 | 157 | -- Transformation Operators 158 | 159 | -- | Collects values from the first BehaviorSubject into an Array, and emits that array only when 160 | -- | second BehaviorSubject emits. 161 | foreign import buffer :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject (Array a) 162 | 163 | -- | Collects values from the past as an array, emits that array when 164 | -- | its size (arg1) reaches the specified buffer size, and starts a new buffer. 165 | -- | The new buffer starts with nth (arg2) element of the BehaviorSubject counting 166 | -- | from the beginning of the *last* buffer. 167 | foreign import bufferCount :: forall a. Int -> Int -> BehaviorSubject a -> BehaviorSubject (Array a) 168 | 169 | -- | Collects values from the past as an array, and emits those arrays 170 | -- | periodically in time. The first argument is how long to fill the buffer. 171 | -- | The second argument is specifies when to open the next buffer following an 172 | -- | emission. The third argument is the maximum size of any buffer. 173 | bufferTime :: forall a. Int -> Int -> Int -> (BehaviorSubject a) -> (BehaviorSubject (Array a)) 174 | bufferTime = runFn4 bufferTimeImpl 175 | 176 | foreign import bufferTimeImpl :: forall a. Fn4 Int Int Int (BehaviorSubject a) (BehaviorSubject (Array a)) 177 | 178 | -- | Collects values from the source BehaviorSubject (arg1) as an array. Starts collecting only when 179 | -- | the opening (arg2) BehaviorSubject emits, and calls the closingSelector function (arg3) to get an BehaviorSubject 180 | -- | that decides when to close the buffer. Another buffer opens when the 181 | -- | opening BehaviorSubject emits its next value. 182 | bufferToggle 183 | :: forall a b c. (BehaviorSubject a) 184 | -> (BehaviorSubject b) 185 | -> (b -> BehaviorSubject c) 186 | -> (BehaviorSubject (Array a)) 187 | bufferToggle = runFn3 bufferToggleImpl 188 | 189 | 190 | foreign import bufferToggleImpl 191 | :: forall a b c. Fn3 (BehaviorSubject a) (BehaviorSubject b) (b -> BehaviorSubject c) (BehaviorSubject (Array a)) 192 | 193 | -- | Collects values from the past as an array. When it starts collecting values, 194 | -- | it calls a function that returns an BehaviorSubject that emits to close the 195 | -- | buffer and restart collecting. 196 | foreign import bufferWhen :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject (Array a) 197 | 198 | -- | Equivalent to mergeMap (a.k.a, `>>=`) EXCEPT that, unlike mergeMap, 199 | -- | the next bind will not run until the BehaviorSubject generated by the projection function (arg2) 200 | -- | completes. That is, composition is sequential, not concurrent. 201 | -- | Warning: if source values arrive endlessly and faster than their corresponding 202 | -- | inner BehaviorSubjects can complete, it will result in memory issues as inner 203 | -- | BehaviorSubjects amass in an unbounded buffer waiting for their turn to be subscribed to. 204 | foreign import concatMap :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject b 205 | 206 | -- | The type signature explains it best. Warning: Like `concatMap`, composition is sequential. 207 | foreign import concatMapTo 208 | :: forall a b c. BehaviorSubject a -> BehaviorSubject b -> (a -> b -> BehaviorSubject c) -> BehaviorSubject c 209 | 210 | -- | It's Like concatMap (a.k.a, `>>=`) EXCEPT that it ignores every new projected 211 | -- | BehaviorSubject if the previous projected BehaviorSubject has not yet completed. 212 | foreign import exhaustMap :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject b 213 | 214 | -- | It's similar to mergeMap, but applies the projection function to every source 215 | -- | value as well as every output value. It's recursive. 216 | foreign import expand :: forall a. BehaviorSubject a -> (a -> BehaviorSubject a) -> BehaviorSubject a 217 | 218 | -- | Groups the items emitted by an BehaviorSubject (arg2) according to the value 219 | -- | returned by the grouping function (arg1). Each group becomes its own 220 | -- | BehaviorSubject. 221 | foreign import groupBy :: forall a b. (a -> b) -> BehaviorSubject a -> BehaviorSubject (BehaviorSubject a) 222 | 223 | foreign import _map :: forall a b. (a -> b) -> BehaviorSubject a -> BehaviorSubject b 224 | 225 | -- | Emits the given constant value on the output BehaviorSubject every time 226 | -- | the source BehaviorSubject emits a value. 227 | foreign import mapTo :: forall a b. b -> BehaviorSubject a -> BehaviorSubject b 228 | 229 | -- | Maps each value to an BehaviorSubject, then flattens all of these BehaviorSubjects 230 | -- | using mergeAll. It's just monadic `bind`. 231 | foreign import mergeMap :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject b 232 | 233 | -- | Maps each value of the BehaviorSubject (arg1) to the same inner BehaviorSubject (arg2), 234 | -- | then flattens the result. 235 | foreign import mergeMapTo :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject b 236 | 237 | -- | Puts the current value and previous value together as an array, and emits that. 238 | foreign import pairwise :: forall a. BehaviorSubject a -> BehaviorSubject (Array a) 239 | 240 | -- | Given a predicate function (arg1), and an BehaviorSubject (arg2), it outputs a 241 | -- | two element array of partitioned values 242 | -- | (i.e., [ BehaviorSubject valuesThatPassPredicate, BehaviorSubject valuesThatFailPredicate ]). 243 | foreign import partition :: forall a. (a -> Boolean) -> BehaviorSubject a -> Array (BehaviorSubject a) 244 | 245 | -- | Given an accumulator function (arg1), an initial value (arg2), and 246 | -- | a source BehaviorSubject (arg3), it returns an BehaviorSubject that emits the current 247 | -- | accumlation whenever the source emits a value. 248 | foreign import scan :: forall a b. (a -> b -> b) -> b -> BehaviorSubject a -> BehaviorSubject b 249 | 250 | -- | Projects each source value to an BehaviorSubject which is merged in the output 251 | -- | BehaviorSubject, emitting values only from the most recently projected BehaviorSubject. 252 | foreign import switchMap :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject b 253 | 254 | -- | It's like switchMap, but maps each value to the same inner BehaviorSubject. 255 | foreign import switchMapTo :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject b 256 | 257 | -- | It's like buffer, but emits a nested BehaviorSubject instead of an array. 258 | foreign import window :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject (BehaviorSubject a) 259 | 260 | -- | It's like bufferCount, but emits a nested BehaviorSubject instead of an array. 261 | foreign import windowCount :: forall a. Int -> Int -> BehaviorSubject a -> BehaviorSubject (BehaviorSubject a) 262 | 263 | -- | It's like bufferTime, but emits a nested BehaviorSubject instead of an array, 264 | -- | and it doesn't take a maximum size parameter. arg1 is how long to 265 | -- | buffer items into a new BehaviorSubject, arg2 is the when the next buffer should begin, 266 | -- | and arg3 is the source BehaviorSubject. 267 | foreign import windowTime :: forall a. Int -> Int -> BehaviorSubject a -> BehaviorSubject (BehaviorSubject a) 268 | 269 | -- | It's like bufferToggle, but emits a nested BehaviorSubject instead of an array. 270 | windowToggle 271 | :: forall a b c. (BehaviorSubject a) 272 | -> (BehaviorSubject b) 273 | -> (b -> BehaviorSubject c) 274 | -> (BehaviorSubject (Array a)) 275 | windowToggle = runFn3 windowToggleImpl 276 | 277 | foreign import windowToggleImpl 278 | :: forall a b c. Fn3 (BehaviorSubject a) (BehaviorSubject b) (b -> BehaviorSubject c) (BehaviorSubject (Array a)) 279 | 280 | -- | It's like bufferWhen, but emits a nested BehaviorSubject instead of an array. 281 | foreign import windowWhen :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject (BehaviorSubject a) 282 | 283 | -- Filtering Operators 284 | 285 | -- | It's like auditTime, but the silencing duration is determined by a second BehaviorSubject. 286 | foreign import audit :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject a 287 | 288 | -- | Ignores source values for duration milliseconds, 289 | -- | then emits the most recent value from the source BehaviorSubject, then repeats this process. 290 | foreign import auditTime :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 291 | 292 | -- | It's like debounceTime, but the time span of emission silence is determined 293 | -- | by a second BehaviorSubject. Allows for a variable debounce rate. 294 | foreign import debounce :: forall a. BehaviorSubject a -> (a -> BehaviorSubject Int) -> BehaviorSubject a 295 | 296 | -- | It's like delay, but passes only the most recent value from each burst of emissions. 297 | foreign import debounceTime :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 298 | 299 | -- | Returns an BehaviorSubject that emits all items emitted by the source BehaviorSubject 300 | -- | that are distinct by comparison from previous items. 301 | foreign import distinct :: forall a. BehaviorSubject a -> BehaviorSubject a 302 | 303 | -- | Returns an BehaviorSubject that emits all items emitted by the source BehaviorSubject 304 | -- | that are distinct by comparison from the previous item. 305 | foreign import distinctUntilChanged :: forall a. BehaviorSubject a -> BehaviorSubject a 306 | 307 | -- | Emits the single value at the specified index in a sequence of emissions 308 | -- | from the source BehaviorSubject. 309 | foreign import elementAt :: forall a. BehaviorSubject a -> Int -> BehaviorSubject a 310 | 311 | -- | Filter items emitted by the source BehaviorSubject by only emitting those that 312 | -- | satisfy a specified predicate. 313 | foreign import filter :: forall a. (a -> Boolean) -> BehaviorSubject a -> BehaviorSubject a 314 | 315 | -- | Ignores all items emitted by the source BehaviorSubject and only passes calls of complete or error. 316 | foreign import ignoreElements :: forall a. BehaviorSubject a -> BehaviorSubject a 317 | 318 | -- | Returns an BehaviorSubject that emits only the last item emitted by the source BehaviorSubject. 319 | foreign import last :: forall a. BehaviorSubject a -> BehaviorSubject a 320 | 321 | -- | It's like sampleTime, but samples whenever the notifier BehaviorSubject emits something. 322 | foreign import sample :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject a 323 | 324 | -- | Periodically looks at the source BehaviorSubject and emits whichever 325 | -- | value it has most recently emitted since the previous sampling, unless the source has not emitted anything since the previous sampling. 326 | foreign import sampleTime :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 327 | 328 | -- | Returns an BehaviorSubject that skips n items emitted by an BehaviorSubject. 329 | foreign import skip :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 330 | 331 | -- | Returns an BehaviorSubject that skips items emitted by the source BehaviorSubject until a second BehaviorSubject emits an item. 332 | foreign import skipUntil :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject a 333 | 334 | -- | Returns an BehaviorSubject that skips all items emitted 335 | -- | by the source BehaviorSubject as long as a specified condition holds true, 336 | -- | but emits all further source items as soon as the condition becomes false. 337 | foreign import skipWhile :: forall a. (a -> Boolean) -> BehaviorSubject a -> BehaviorSubject a 338 | 339 | -- | Emits only the first n values emitted by the source BehaviorSubject. 340 | foreign import take :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 341 | 342 | -- | Lets values pass until a second BehaviorSubject emits something. Then, it completes. 343 | foreign import takeUntil :: forall a b. BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject a 344 | 345 | -- | Emits values emitted by the source BehaviorSubject so long as each value satisfies 346 | -- | the given predicate, and then completes as soon as this predicate is not satisfied. 347 | foreign import takeWhile :: forall a. (a -> Boolean) -> BehaviorSubject a -> BehaviorSubject a 348 | 349 | -- | It's like throttleTime, but the silencing duration is determined by a second BehaviorSubject. 350 | foreign import throttle :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject a 351 | 352 | -- | Emits a value from the source BehaviorSubject, then ignores subsequent source values 353 | -- | for duration milliseconds, then repeats this process. 354 | foreign import throttleTime :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 355 | 356 | 357 | -- Combination Operators 358 | 359 | -- | An BehaviorSubject of projected values from the most recent values from each input BehaviorSubject. 360 | foreign import combineLatest 361 | :: forall a b c. (a -> b -> c) -> BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject c 362 | 363 | -- | Concatenates two BehaviorSubjects together by sequentially emitting their values, one BehaviorSubject after the other. 364 | foreign import concat :: forall a. BehaviorSubject a -> BehaviorSubject a -> BehaviorSubject a 365 | 366 | -- | Converts a higher-order BehaviorSubject into a first-order BehaviorSubject by concatenating the inner BehaviorSubjects in order. 367 | foreign import concatAll :: forall a. BehaviorSubject (BehaviorSubject a) -> BehaviorSubject a 368 | 369 | -- | Flattens an BehaviorSubject-of-BehaviorSubjects by dropping the next inner BehaviorSubjects 370 | -- | while the current inner is still executing. 371 | foreign import exhaust :: forall a. BehaviorSubject (BehaviorSubject a) -> BehaviorSubject a 372 | 373 | -- | Creates an output BehaviorSubject which concurrently emits all values from each input BehaviorSubject. 374 | foreign import merge :: forall a. BehaviorSubject a -> BehaviorSubject a -> BehaviorSubject a 375 | 376 | -- | Converts a higher-order BehaviorSubject into a first-order BehaviorSubject 377 | -- | which concurrently delivers all values that are emitted on the inner BehaviorSubjects. 378 | foreign import mergeAll :: forall a. BehaviorSubject (BehaviorSubject a) -> BehaviorSubject a 379 | 380 | -- | Returns an BehaviorSubject that mirrors the first source BehaviorSubject to emit an 381 | -- | item from the array of BehaviorSubjects. 382 | foreign import race :: forall a. Array (BehaviorSubject a) -> BehaviorSubject a 383 | 384 | -- | Returns an BehaviorSubject that emits the items in the given Array before 385 | -- | it begins to emit items emitted by the source BehaviorSubject. 386 | foreign import startWith :: forall a. Array a -> BehaviorSubject a -> BehaviorSubject a 387 | 388 | -- | Combines each value from the source BehaviorSubjects using a project function to 389 | -- | determine the value to be emitted on the output BehaviorSubject. 390 | foreign import withLatestFrom 391 | :: forall a b c. (a -> b -> c) -> BehaviorSubject a -> BehaviorSubject b -> BehaviorSubject c 392 | 393 | -- | Waits for each BehaviorSubject to emit a value. Once this occurs, all values 394 | -- | with the corresponding index will be emitted. This will continue until at 395 | -- | least one inner BehaviorSubject completes. 396 | foreign import zip :: forall a. Array (BehaviorSubject a) -> BehaviorSubject (Array a) 397 | 398 | -- Error Handling Operators 399 | 400 | foreign import catch :: forall a. (BehaviorSubject a) -> (Error -> BehaviorSubject a) -> (BehaviorSubject a) 401 | 402 | -- | If the source BehaviorSubject calls error, this method will resubscribe to the 403 | -- | source BehaviorSubject n times rather than propagating the error call. 404 | foreign import retry :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 405 | 406 | -- Utility Operators 407 | 408 | -- | Time shifts each item by some specified amount of milliseconds. 409 | foreign import delay :: forall a. Int -> BehaviorSubject a -> BehaviorSubject a 410 | 411 | -- | Delays the emission of items from the source BehaviorSubject by a given time 412 | -- | span determined by the emissions of another BehaviorSubject. 413 | foreign import delayWhen :: forall a b. BehaviorSubject a -> (a -> BehaviorSubject b) -> BehaviorSubject a 414 | 415 | foreign import dematerialize :: forall a. BehaviorSubject (Notification a) -> BehaviorSubject a 416 | 417 | foreign import _materialize 418 | :: forall a. 419 | Fn4 420 | (BehaviorSubject a) 421 | (a -> Notification a) 422 | (Error -> Notification a) 423 | (Notification a) 424 | (BehaviorSubject (Notification a)) 425 | 426 | materialize :: forall a. BehaviorSubject a -> BehaviorSubject (Notification a) 427 | materialize ob = runFn4 _materialize ob OnNext OnError OnComplete 428 | -- | Performs the effect on each value of the BehaviorSubject. An alias for `do`. 429 | -- | Useful for testing (transparently performing an effect outside of a subscription). 430 | 431 | foreign import performEach :: forall a e. BehaviorSubject a -> (a -> Eff (|e) Unit) -> Eff (|e) (BehaviorSubject a) 432 | 433 | foreign import toArray :: forall a. BehaviorSubject a -> BehaviorSubject (Array a) 434 | 435 | -- | Returns a BehaviorSubject that emits the items emitted by the source BehaviorSubject or a specified default item 436 | -- | if the source BehaviorSubject is empty. 437 | -- | 438 | -- | ![marble diagram](http://reactivex.io/documentation/operators/images/defaultIfEmpty.c.png) 439 | -- | 440 | -- | takes a defaultValue which is the item to emit if the source BehaviorSubject emits no items. 441 | -- | 442 | -- | returns a BehaviorSubject that emits either the specified default item if the source BehaviorSubject emits no 443 | -- | items, or the items emitted by the source BehaviorSubject 444 | foreign import defaultIfEmpty :: forall a. BehaviorSubject a -> a -> BehaviorSubject a 445 | 446 | -- | Determines whether all elements of a BehaviorSubject satisfy a condition. 447 | -- | Returns a BehaviorSubject containing a single element determining whether all 448 | -- | elements in the source BehaviorSubject pass the test in the specified predicate. 449 | foreign import every :: forall a. BehaviorSubject a -> (a -> Boolean) -> BehaviorSubject Boolean 450 | 451 | -- | Tests whether this `BehaviorSubject` emits no elements. 452 | -- | 453 | -- | returns a BehaviorSubject emitting one single Boolean, which is `true` if this `BehaviorSubject` 454 | -- | emits no elements, and `false` otherwise. 455 | foreign import isEmpty :: forall a. BehaviorSubject a -> BehaviorSubject Boolean 456 | 457 | -- | Returns a BehaviorSubject that emits only the first item emitted by the source 458 | -- | BehaviorSubject that satisfies the given predicate. 459 | foreign import first :: forall a. BehaviorSubject a -> (a -> Boolean) -> BehaviorSubject a 460 | 461 | 462 | -- Aggregate Operators 463 | 464 | -- | Counts the number of emissions on the source and emits that number when the source completes. 465 | foreign import count :: forall a. BehaviorSubject a -> BehaviorSubject Int 466 | 467 | -- | Applies an accumulator function over the source, and returns the accumulated 468 | -- | result when the source completes, given a seed value. 469 | foreign import reduce :: forall a b. (a -> b -> b) -> b -> BehaviorSubject a -> BehaviorSubject b 470 | 471 | -- Helper Functions 472 | 473 | -- | Run a source's effects 474 | foreign import unwrap :: forall a e. BehaviorSubject (Eff e a) -> Eff e (BehaviorSubject a) 475 | -------------------------------------------------------------------------------- /src/RxJS/Notification.purs: -------------------------------------------------------------------------------- 1 | 2 | module RxJS.Notification where 3 | 4 | import Prelude 5 | import Control.Monad.Eff.Exception (Error(), message) 6 | 7 | data Notification a = OnError Error | OnNext a | OnComplete 8 | 9 | instance showNotification :: (Show a) => Show (Notification a) where 10 | show (OnNext v) = "(OnNext " <> show v <> ")" 11 | show (OnError err) = "(OnError " <> message err <> ")" 12 | show (OnComplete) = "(OnComplete)" 13 | -------------------------------------------------------------------------------- /src/RxJS/Observable.js: -------------------------------------------------------------------------------- 1 | /* global exports */ 2 | "use strict"; 3 | 4 | // module RxJS.Observable 5 | 6 | var Rx = require('rxjs'); 7 | 8 | /**** Scheduling ****/ 9 | 10 | exports.observeOn = function(s){ 11 | return function(obs){ 12 | return obs.observeOn(s); 13 | }; 14 | } 15 | 16 | exports.subscribeOn = function(s){ 17 | return function(obs){ 18 | return obs.subscribeOn(s); 19 | }; 20 | } 21 | 22 | /**** Subscription ****/ 23 | exports.subscribe = function(sub){ 24 | return function(obs) { 25 | return function(){ 26 | return obs.subscribe( 27 | function(val){ sub.next(val)();}, 28 | function(err){ sub.error(err)();}, 29 | function(){sub.complete()();} 30 | ); 31 | }; 32 | }; 33 | } 34 | 35 | exports.subscribeNext = function (eff){ 36 | return function(obs){ 37 | return function(){ 38 | obs.subscribe( 39 | function(val){return eff(val)();} 40 | ); 41 | }; 42 | }; 43 | } 44 | 45 | 46 | /**** Creation Operators ****/ 47 | 48 | exports.ajax = function(req) { 49 | return function() { 50 | return Rx.Observable.ajax(req) 51 | .map(function(res){ 52 | var body = res.responseText || JSON.stringify(res.response) 53 | return {body: body, status: res.status, responseType: res.responseType} 54 | }) 55 | } 56 | } 57 | 58 | exports.ajaxWithBody = exports.ajax; 59 | 60 | exports._empty = Rx.Observable.empty(); 61 | 62 | exports.fromArray = Rx.Observable.from; 63 | 64 | exports.fromEventImpl = Rx.Observable.fromEvent; 65 | 66 | exports.interval = Rx.Observable.interval; 67 | 68 | exports.just = Rx.Observable.of; 69 | 70 | exports.never = Rx.Observable.never(); 71 | 72 | exports.rangeImpl = Rx.Observable.range; 73 | 74 | exports.throw = Rx.Observable.throw; 75 | 76 | exports.timerImpl = Rx.Observable.timer; 77 | 78 | /**** Transformation Operators ****/ 79 | 80 | exports.buffer = function(obs1){ 81 | return function(obs2){ 82 | return obs1.buffer(obs2); 83 | }; 84 | } 85 | 86 | exports.bufferCount = function(maxSize){ 87 | return function(startNewAt){ 88 | return function(obs){ 89 | return obs.bufferCount(maxSize, startNewAt); 90 | }; 91 | }; 92 | } 93 | 94 | exports.bufferTimeImpl = function(timespan, creationInterval, maxSize, obs){ 95 | return obs.bufferTime(timespan, creationInterval, maxSize); 96 | } 97 | 98 | exports.bufferToggleImpl = function(obs, openings, closingSelector){ 99 | return obs.bufferToggle(openings, closingSelector); 100 | } 101 | 102 | exports.bufferWhen = function(obs){ 103 | return function(closing){ 104 | return obs.bufferWhen(closing); 105 | }; 106 | } 107 | 108 | exports.concatMap = function(obs){ 109 | return function(f){ 110 | return obs.concatMap(f); 111 | }; 112 | } 113 | 114 | exports.concatMapTo = function(obs1){ 115 | return function(obs2){ 116 | return function(f){ 117 | return obs1.concatMapTo(obs2, function(a, b){ 118 | return f(a)(b); 119 | }); 120 | }; 121 | }; 122 | } 123 | 124 | exports.exhaustMap = function(obs){ 125 | return function(f){ 126 | return obs.exhaustMap(f); 127 | }; 128 | } 129 | 130 | exports.expand = function(obs){ 131 | return function(f){ 132 | return obs.expand(f); 133 | }; 134 | } 135 | 136 | exports.share = function(obs){ 137 | return obs.share() 138 | } 139 | 140 | exports.groupBy = function(f){ 141 | return function(obs){ 142 | return obs.groupBy(f); 143 | }; 144 | } 145 | 146 | exports._map = function(f){ 147 | return function(obs){ 148 | return obs.map(f); 149 | }; 150 | } 151 | 152 | exports.mapTo = function(val){ 153 | return function(obs1){ 154 | return obs1.mapTo(val); 155 | }; 156 | } 157 | 158 | exports.mergeMap = function(obs){ 159 | return function(f){ 160 | return obs.mergeMap(f); 161 | }; 162 | } 163 | 164 | 165 | exports.mergeMapTo = function(obs1){ 166 | return function(obs2){ 167 | return obs1.mergeMapTo(obs2); 168 | }; 169 | } 170 | 171 | exports.pairwise = function(obs){ 172 | return obs.pairwise(); 173 | } 174 | 175 | exports.partition = function(pred){ 176 | return function(obs){ 177 | return obs.partition(pred); 178 | }; 179 | } 180 | 181 | exports.scan = function scan(f) { 182 | return function(seed) { 183 | return function(ob) { 184 | return ob.scan(function(acc, value) { 185 | return f(value)(acc); 186 | }, seed); 187 | }; 188 | }; 189 | } 190 | 191 | exports.switchMap = function(obs){ 192 | return function(f){ 193 | return obs.switchMap(f); 194 | }; 195 | } 196 | 197 | exports.switchMapTo = function(obs1){ 198 | return function(obs2){ 199 | return obs1.switchMapTo(obs2); 200 | }; 201 | } 202 | 203 | exports.window = function(obs1){ 204 | return function(obs2){ 205 | return obs1.window(obs2); 206 | }; 207 | } 208 | 209 | exports.windowCount = function(maxSize){ 210 | return function(startNewAt){ 211 | return function(obs){ 212 | return obs.windowCount(maxSize, startNewAt); 213 | }; 214 | }; 215 | } 216 | 217 | exports.windowTime = function(timeSpan){ 218 | return function(startNewAt){ 219 | return function(obs){ 220 | return obs.windowTime(timeSpan, startNewAt); 221 | }; 222 | }; 223 | } 224 | 225 | exports.windowToggleImpl = function(obs, openings, closingSelector){ 226 | return obs.windowToggle(openings, closingSelector); 227 | } 228 | 229 | exports.windowWhen = function(obs){ 230 | return function(closing){ 231 | return obs.windowWhen(function() { return closing }); 232 | }; 233 | } 234 | 235 | /**** Filtering Operators ****/ 236 | 237 | exports.audit = function(obs){ 238 | return function(f){ 239 | return obs.audit(f); 240 | }; 241 | } 242 | 243 | exports.auditTime = function(ms){ 244 | return function(obs){ 245 | return obs.auditTime(ms); 246 | }; 247 | } 248 | 249 | exports.debounce = function (ob) { 250 | return function(f) { 251 | return ob.debounce(f); 252 | }; 253 | } 254 | 255 | exports.debounceTime = function(ms) { 256 | return function(obs){ 257 | return obs.debounceTime(ms); 258 | }; 259 | } 260 | 261 | exports.distinct = function (ob){ 262 | return ob.distinct(); 263 | } 264 | 265 | exports.distinctUntilChanged = function (ob){ 266 | return ob.distinctUntilChanged(); 267 | } 268 | 269 | exports.elementAt = function(obs){ 270 | return function(i){ 271 | return obs.elementAt(i); 272 | }; 273 | } 274 | 275 | exports.filter = function (p){ 276 | return function(ob){ 277 | return ob.filter(p); 278 | }; 279 | } 280 | 281 | exports.first = function(ob){ 282 | return function(p){ 283 | return ob.first(p); 284 | }; 285 | } 286 | 287 | exports.ignoreElements = function(obs){ 288 | return obs.ignoreElements(); 289 | } 290 | 291 | exports.last = function(ob){ 292 | return function(p){ 293 | return ob.first(p); 294 | }; 295 | } 296 | 297 | exports.sample = function(obs1){ 298 | return function(obs2){ 299 | return obs1.sample(obs2); 300 | }; 301 | } 302 | 303 | exports.sampleTime = function(ms){ 304 | return function(obs){ 305 | return obs.sampleTime(ms); 306 | }; 307 | } 308 | 309 | exports.skip = function(n){ 310 | return function(obs){ 311 | return obs.skip(n); 312 | }; 313 | } 314 | 315 | exports.skipUntil = function(obs1){ 316 | return function(obs2){ 317 | return obs1.skipUntil(obs2); 318 | }; 319 | } 320 | 321 | exports.skipWhile = function (p){ 322 | return function(obs){ 323 | return obs.skipWhile(p); 324 | }; 325 | } 326 | 327 | exports.take = function (n) { 328 | return function(ob) { 329 | return ob.take(n); 330 | }; 331 | } 332 | 333 | exports.takeUntil = function (other) { 334 | return function(ob) { 335 | return ob.takeUntil(other); 336 | }; 337 | } 338 | 339 | exports.takeWhile = function (p){ 340 | return function(obs){ 341 | return obs.takeWhile(p); 342 | }; 343 | } 344 | 345 | exports.throttle = function(obs){ 346 | return function(f){ 347 | return obs.throttle(f); 348 | }; 349 | } 350 | 351 | exports.throttleTime = function(ms){ 352 | return function(obs){ 353 | return obs.throttleTime(ms); 354 | }; 355 | } 356 | 357 | /**** Combination Operators ****/ 358 | 359 | exports.combineLatest = function (f) { 360 | return function(ob1) { 361 | return function(ob2) { 362 | return ob1.combineLatest(ob2, function (x, y) { 363 | return f(x)(y); 364 | }); 365 | }; 366 | }; 367 | } 368 | 369 | exports.combineLatest3 = function(f){ 370 | return function(obs1){ 371 | return function(obs2){ 372 | return function(obs3){ 373 | return obs1.combineLatest(obs2, obs3, function(x,y,z){ 374 | return f(x)(y)(z); 375 | }); 376 | }; 377 | }; 378 | }; 379 | } 380 | 381 | exports.concat = function (obs1) { 382 | return function(obs2) { 383 | return obs1.concat(obs1); 384 | }; 385 | } 386 | 387 | exports.concatAll = function (obsobs){ 388 | return obsobs.concatAll(); 389 | } 390 | 391 | exports.exhaust = function (obsobs){ 392 | return obsobs.exhaust(); 393 | } 394 | 395 | exports.merge = function (ob) { 396 | return function(other) { 397 | return ob.merge(other); 398 | }; 399 | } 400 | 401 | exports.mergeAll = function (obsobs){ 402 | return obsobs.mergeAll(); 403 | } 404 | 405 | exports.race = function(arrOfObs){ 406 | return Rx.Observable.race.apply(this, arrOfObs); 407 | } 408 | 409 | exports.startWith = function (start) { 410 | return function(ob) { 411 | return ob.startWith(start); 412 | }; 413 | } 414 | 415 | exports.withLatestFrom = function (f) { 416 | return function (ob1) { 417 | return function (ob2) { 418 | return ob1.withLatestFrom(ob2, function(x, y) { 419 | return f(x)(y); 420 | }) 421 | }; 422 | }; 423 | } 424 | 425 | exports.zip = function(arrOfObs){ 426 | return Rx.Observable.zip.apply(this, arrOfObs); 427 | } 428 | 429 | /**** Error Handling Operators ****/ 430 | 431 | exports.catch = function(obs){ 432 | return function(f){ 433 | return obs.catch(f); 434 | }; 435 | } 436 | 437 | exports.retry = function(nTimes){ 438 | return function(obs){ 439 | return obs.retry(nTimes); 440 | }; 441 | } 442 | 443 | 444 | /**** Utility Operators ****/ 445 | 446 | exports.delay = function (ms){ 447 | return function(ob){ 448 | return ob.delay(ms); 449 | }; 450 | } 451 | 452 | exports.delayWhen = function(obs1){ 453 | return function(f){ 454 | return obs1.delayWhen(f); 455 | }; 456 | } 457 | 458 | exports._materialize = function (ob, Next, Error, Complete) { 459 | return ob.materialize().map(function(x) { 460 | switch (x.kind) { 461 | case 'N': return Next(x.value); 462 | case 'E': return Error(x.error); 463 | case 'C': return Complete; 464 | } 465 | }); 466 | } 467 | 468 | exports.dematerialize = function (ob) { 469 | return ob.map(function(a) { 470 | switch (a.constructor.name) { 471 | case "OnNext": return Rx.Notification.createNext(a.value0); 472 | case "OnError": return Rx.Notification.createError(a.value0); 473 | case "OnComplete": return Rx.Notification.createComplete(); 474 | } 475 | }).dematerialize(); 476 | } 477 | 478 | exports.performEach = function(obs){ 479 | return function(f){ 480 | return function(){ 481 | return obs.do(function(val){ 482 | f(val)(); 483 | }); 484 | }; 485 | }; 486 | } 487 | 488 | exports.toArray = function(obs){ 489 | return obs.toArray(); 490 | } 491 | 492 | /**** Conditional and Boolean Operators ****/ 493 | 494 | exports.defaultIfEmpty = function(obs){ 495 | return function(val){ 496 | return obs.defaultIfEmpty(val); 497 | }; 498 | } 499 | 500 | exports.every = function(obs){ 501 | return function(pred){ 502 | return obs.every(pred); 503 | }; 504 | } 505 | 506 | exports.isEmpty = function(obs){ 507 | return obs.isEmpty(); 508 | } 509 | 510 | /**** Aggregate Operators ****/ 511 | 512 | exports.count = function(obs){ 513 | return obs.count(); 514 | } 515 | 516 | 517 | exports.reduce = function (f){ 518 | return function(seed){ 519 | return function(ob){ 520 | return ob.reduce(function (x, y) { 521 | return f(x)(y); 522 | }, seed); 523 | }; 524 | }; 525 | } 526 | 527 | 528 | /**** Helpers ****/ 529 | 530 | exports.unwrap = function (obs) { 531 | return function() { 532 | return obs.map(function(eff) { 533 | return eff(); 534 | }); 535 | }; 536 | } 537 | -------------------------------------------------------------------------------- /src/RxJS/ReplaySubject.js: -------------------------------------------------------------------------------- 1 | /* global exports */ 2 | "use strict"; 3 | 4 | // module RxJS.ReplaySubject 5 | 6 | var Rx = require('rxjs'); 7 | 8 | /**** Scheduling ****/ 9 | 10 | exports.observeOn = function(s){ 11 | return function(obs){ 12 | return obs.observeOn(s); 13 | }; 14 | } 15 | 16 | exports.subscribeOn = function(s){ 17 | return function(obs){ 18 | return obs.subscribeOn(s); 19 | }; 20 | } 21 | 22 | /**** Subscription ****/ 23 | 24 | exports.subscribe = function(sub){ 25 | return function(obs) { 26 | return function(){ 27 | return obs.subscribe( 28 | function(val){ sub.next(val)();}, 29 | function(err){ sub.error(err)();}, 30 | function(){sub.complete()();} 31 | ); 32 | }; 33 | }; 34 | } 35 | 36 | exports.subscribeObservableTo = function(obs){ 37 | return function(sub){ 38 | return function(){ 39 | return obs.subscribe(sub); 40 | }; 41 | }; 42 | } 43 | 44 | exports.subscribeNext = function (eff){ 45 | return function(obs){ 46 | return function(){ 47 | obs.subscribe( 48 | function(val){return eff(val)();} 49 | ); 50 | }; 51 | }; 52 | } 53 | 54 | /**** Creation Operator ****/ 55 | 56 | exports._empty = function (){ 57 | return new Rx.ReplaySubject(); 58 | } 59 | 60 | exports.just = function(val){ 61 | return new Rx.ReplaySubject(val); 62 | } 63 | 64 | /**** ReplaySubject Operators ****/ 65 | 66 | exports.asObservable = function(rs){ 67 | return bs.asObservable(); 68 | } 69 | 70 | exports.next = function(val){ 71 | return function(rs){ 72 | return function(){ 73 | rs.next(val); 74 | }; 75 | }; 76 | } 77 | 78 | 79 | /**** Transformation Operators ****/ 80 | 81 | exports.buffer = function(obs1){ 82 | return function(obs2){ 83 | return obs1.buffer(obs2); 84 | }; 85 | } 86 | 87 | exports.bufferCount = function(maxSize){ 88 | return function(startNewAt){ 89 | return function(obs){ 90 | return obs.bufferCount(maxSize, startNewAt); 91 | }; 92 | }; 93 | } 94 | 95 | exports.bufferTimeImpl = function(timespan, creationInterval, maxSize, obs){ 96 | return obs.bufferTime(timespan, creationInterval, maxSize); 97 | } 98 | 99 | exports.bufferToggleImpl = function(obs, openings, closingSelector){ 100 | return obs.bufferToggle(openings, closingSelector); 101 | } 102 | 103 | exports.bufferWhen = function(obs){ 104 | return function(closing){ 105 | return obs.bufferWhen(closing); 106 | }; 107 | } 108 | 109 | exports.concatMap = function(obs){ 110 | return function(f){ 111 | return obs.concatMap(f); 112 | }; 113 | } 114 | 115 | exports.concatMapTo = function(obs1){ 116 | return function(obs2){ 117 | return function(f){ 118 | return obs1.concatMapTo(obs2, function(a, b){ 119 | return f(a)(b); 120 | }); 121 | }; 122 | }; 123 | } 124 | 125 | exports.exhaustMap = function(obs){ 126 | return function(f){ 127 | return obs.exhaustMap(f); 128 | }; 129 | } 130 | 131 | exports.expand = function(obs){ 132 | return function(f){ 133 | return obs.expand(f); 134 | }; 135 | } 136 | 137 | exports.groupBy = function(f){ 138 | return function(obs){ 139 | return obs.groupBy(f); 140 | }; 141 | } 142 | 143 | exports._map = function(f){ 144 | return function(obs){ 145 | return obs.map(f); 146 | }; 147 | } 148 | 149 | exports.mapTo = function(val){ 150 | return function(obs1){ 151 | return obs1.mapTo(val); 152 | }; 153 | } 154 | 155 | exports.mergeMap = function(obs){ 156 | return function(f){ 157 | return obs.mergeMap(f); 158 | }; 159 | } 160 | 161 | 162 | exports.mergeMapTo = function(obs1){ 163 | return function(obs2){ 164 | return obs1.mergeMapTo(obs2); 165 | }; 166 | } 167 | 168 | exports.pairwise = function(obs){ 169 | return obs.pairwise(); 170 | } 171 | 172 | exports.partition = function(pred){ 173 | return function(obs){ 174 | return obs.partition(pred); 175 | }; 176 | } 177 | 178 | exports.scan = function scan(f) { 179 | return function(seed) { 180 | return function(ob) { 181 | return ob.scan(function(acc, value) { 182 | return f(value)(acc); 183 | }, seed); 184 | }; 185 | }; 186 | } 187 | 188 | exports.switchMap = function(obs){ 189 | return function(f){ 190 | return obs.switchMap(f); 191 | }; 192 | } 193 | 194 | exports.switchMapTo = function(obs1){ 195 | return function(obs2){ 196 | return obs1.switchMapTo(obs2); 197 | }; 198 | } 199 | 200 | exports.window = function(obs1){ 201 | return function(obs2){ 202 | return obs1.window(obs2); 203 | }; 204 | } 205 | 206 | exports.windowCount = function(maxSize){ 207 | return function(startNewAt){ 208 | return function(obs){ 209 | return obs.windowCount(maxSize, startNewAt); 210 | }; 211 | }; 212 | } 213 | 214 | exports.windowTime = function(timeSpan){ 215 | return function(startNewAt){ 216 | return function(obs){ 217 | return obs.windowTime(timeSpan, startNewAt); 218 | }; 219 | }; 220 | } 221 | 222 | exports.windowToggleImpl = function(obs, openings, closingSelector){ 223 | return obs.windowToggle(openings, closingSelector); 224 | } 225 | 226 | exports.windowWhen = function(obs){ 227 | return function(closing){ 228 | return obs.windowWhen(closing); 229 | }; 230 | } 231 | 232 | /**** Filtering Operators ****/ 233 | 234 | exports.audit = function(obs){ 235 | return function(f){ 236 | return obs.audit(f); 237 | }; 238 | } 239 | 240 | exports.auditTime = function(ms){ 241 | return function(obs){ 242 | return obs.auditTime(ms); 243 | }; 244 | } 245 | 246 | exports.debounce = function (ob) { 247 | return function(f) { 248 | return ob.debounce(f); 249 | }; 250 | } 251 | 252 | exports.debounceTime = function(ms) { 253 | return function(obs){ 254 | return obs.debounceTime(ms); 255 | }; 256 | } 257 | 258 | exports.distinct = function (ob){ 259 | return ob.distinct(); 260 | } 261 | 262 | exports.distinctUntilChanged = function (ob){ 263 | return ob.distinctUntilChanged(); 264 | } 265 | 266 | exports.elementAt = function(obs){ 267 | return function(i){ 268 | return obs.elementAt(i); 269 | }; 270 | } 271 | 272 | exports.filter = function (p){ 273 | return function(ob){ 274 | return ob.filter(p); 275 | }; 276 | } 277 | 278 | exports.first = function (p){ 279 | return function(ob){ 280 | return ob.first(p); 281 | }; 282 | } 283 | 284 | exports.ignoreElements = function(obs){ 285 | return obs.ignoreElements(); 286 | } 287 | 288 | exports.last = function (ob){ 289 | return ob.last(); 290 | } 291 | 292 | exports.sample = function(obs1){ 293 | return function(obs2){ 294 | return obs1.sample(obs2); 295 | }; 296 | } 297 | 298 | exports.sampleTime = function(ms){ 299 | return function(obs){ 300 | return obs.sampleTime(ms); 301 | }; 302 | } 303 | 304 | exports.skip = function(n){ 305 | return function(obs){ 306 | return obs.skip(n); 307 | }; 308 | } 309 | 310 | exports.skipUntil = function(obs1){ 311 | return function(obs2){ 312 | return obs1.skipUntil(obs2); 313 | }; 314 | } 315 | 316 | exports.skipWhile = function (p){ 317 | return function(obs){ 318 | return obs.skipWhile(p); 319 | }; 320 | } 321 | 322 | exports.take = function (n) { 323 | return function(ob) { 324 | return ob.take(n); 325 | }; 326 | } 327 | 328 | exports.takeUntil = function (other) { 329 | return function(ob) { 330 | return ob.takeUntil(other); 331 | }; 332 | } 333 | 334 | exports.takeWhile = function (p){ 335 | return function(obs){ 336 | return obs.takeWhile(p); 337 | }; 338 | } 339 | 340 | exports.throttle = function(obs){ 341 | return function(f){ 342 | return obs.throttle(f); 343 | }; 344 | } 345 | 346 | exports.throttleTime = function(obs){ 347 | return function(ms){ 348 | return obs.throttleTime(ms); 349 | }; 350 | } 351 | 352 | /**** Combination Operators ****/ 353 | 354 | exports.combineLatest = function (f) { 355 | return function(ob1) { 356 | return function(ob2) { 357 | return ob1.combineLatest(ob2, function (x, y) { 358 | return f(x)(y); 359 | }); 360 | }; 361 | }; 362 | } 363 | 364 | exports.concat = function (obs1) { 365 | return function(obs2) { 366 | return obs1.concat(obs1); 367 | }; 368 | } 369 | 370 | exports.concatAll = function (obsobs){ 371 | return obsobs.concatAll(); 372 | } 373 | 374 | exports.exhaust = function (obsobs){ 375 | return obsobs.exhaust(); 376 | } 377 | 378 | exports.merge = function (ob) { 379 | return function(other) { 380 | return ob.merge(other); 381 | }; 382 | } 383 | 384 | exports.mergeAll = function (obsobs){ 385 | return obsobs.mergeAll(); 386 | } 387 | 388 | exports.race = function(arrOfObs){ 389 | return Rx.ReplaySubject.race.apply(this, arrOfObs); 390 | } 391 | 392 | exports.startWith = function (start) { 393 | return function(ob) { 394 | return ob.startWith(start); 395 | }; 396 | } 397 | 398 | 399 | exports.withLatestFrom = function (f) { 400 | return function (ob1) { 401 | return function (ob2) { 402 | return ob1.withLatestFrom(ob2, function(x, y) { 403 | return f(x)(y); 404 | }) 405 | }; 406 | }; 407 | } 408 | 409 | exports.zip = function(arrOfObs){ 410 | return Rx.ReplaySubject.zip.apply(this, arrOfObs); 411 | } 412 | 413 | /**** Error Handling Operators ****/ 414 | 415 | exports.catch = function(obs){ 416 | return function(f){ 417 | return obs.catch(f); 418 | }; 419 | } 420 | 421 | exports.retry = function(nTimes){ 422 | return function(obs){ 423 | return obs.retry(nTimes); 424 | }; 425 | } 426 | 427 | 428 | /**** Utility Operators ****/ 429 | 430 | exports.delay = function (ms){ 431 | return function(ob){ 432 | return ob.delay(ms); 433 | }; 434 | } 435 | 436 | exports.delayWhen = function(obs1){ 437 | return function(f){ 438 | return obs1.delayWhen(f); 439 | }; 440 | } 441 | 442 | exports._materialize = function (ob, Next, Error, Complete) { 443 | return ob.materialize().map(function(x) { 444 | switch (x.kind) { 445 | case 'N': return Next(x.value); 446 | case 'E': return Error(x.error); 447 | case 'C': return Complete; 448 | } 449 | }); 450 | } 451 | 452 | exports.dematerialize = function (ob) { 453 | return ob.map(function(a) { 454 | switch (a.constructor.name) { 455 | case "OnNext": return Rx.Notification.createNext(a.value0); 456 | case "OnError": return Rx.Notification.createError(a.value0); 457 | case "OnComplete": return Rx.Notification.createComplete(); 458 | } 459 | }).dematerialize(); 460 | } 461 | 462 | exports.performEach = function(obs){ 463 | return function(f){ 464 | return function(){ 465 | return obs.do(function(val){ 466 | f(val)(); 467 | }); 468 | }; 469 | }; 470 | } 471 | 472 | 473 | exports.toArray = function(obs){ 474 | return obs.toArray(); 475 | } 476 | 477 | /**** Conditional and Boolean Operators ****/ 478 | 479 | exports.defaultIfEmpty = function(obs){ 480 | return function(val){ 481 | return obs.defaultIfEmpty(val); 482 | }; 483 | } 484 | 485 | exports.every = function(pred){ 486 | return function(obs){ 487 | return obs.every(pred); 488 | }; 489 | } 490 | 491 | exports.isEmpty = function(obs){ 492 | return obs.isEmpty(); 493 | } 494 | 495 | /**** Aggregate Operators ****/ 496 | 497 | exports.count = function(obs){ 498 | return obs.count(); 499 | } 500 | 501 | 502 | exports.reduce = function (f){ 503 | return function(seed){ 504 | return function(ob){ 505 | return ob.reduce(function (x, y) { 506 | return f(x)(y); 507 | }, seed); 508 | }; 509 | }; 510 | } 511 | 512 | /**** Helpers ****/ 513 | 514 | exports.unwrap = function (obs) { 515 | return function() { 516 | return obs.map(function(eff) { 517 | return eff(); 518 | }); 519 | }; 520 | } 521 | -------------------------------------------------------------------------------- /src/RxJS/ReplaySubject.purs: -------------------------------------------------------------------------------- 1 | module RxJS.ReplaySubject 2 | ( ReplaySubject(..) 3 | , observeOn 4 | , subscribeOn 5 | , subscribe 6 | , subscribeNext 7 | , just 8 | , next 9 | , send 10 | , asObservable 11 | , buffer 12 | , bufferCount 13 | , bufferToggle 14 | , bufferWhen 15 | , concatMap 16 | , concatMapTo 17 | , exhaustMap 18 | , expand 19 | , groupBy 20 | , mapTo 21 | , mergeMap 22 | , mergeMapTo 23 | , pairwise 24 | , partition 25 | , scan 26 | , switchMap 27 | , switchMapTo 28 | , window 29 | , windowCount 30 | , windowTime 31 | , windowToggle 32 | , windowWhen 33 | , audit 34 | , auditTime 35 | , debounce 36 | , debounceTime 37 | , distinct 38 | , distinctUntilChanged 39 | , elementAt 40 | , filter 41 | , ignoreElements 42 | , last 43 | , sample 44 | , sampleTime 45 | , skip 46 | , skipUntil 47 | , skipWhile 48 | , take 49 | , takeUntil 50 | , takeWhile 51 | , throttle 52 | , throttleTime 53 | , combineLatest 54 | , concat 55 | , concatAll 56 | , exhaust 57 | , merge 58 | , mergeAll 59 | , race 60 | , startWith 61 | , withLatestFrom 62 | , zip 63 | , catch 64 | , retry 65 | , delay 66 | , delayWhen 67 | , dematerialize 68 | , materialize 69 | , performEach 70 | , toArray 71 | , count 72 | ) where 73 | 74 | 75 | import RxJS.Scheduler (Scheduler) 76 | import Control.Alt (class Alt) 77 | import Control.Alternative (class Alternative) 78 | import Control.Monad.Eff (Eff) 79 | import Control.Monad.Eff.Exception (Error) 80 | import Control.MonadPlus (class MonadPlus) 81 | import Control.MonadZero (class MonadZero) 82 | import Control.Plus (class Plus) 83 | import Data.Function.Uncurried (Fn3, Fn4, runFn3, runFn4) 84 | import Prelude (class Semigroup, class Monad, class Bind, class Applicative, class Apply, class Functor, Unit, id, unit) 85 | import RxJS.Notification (Notification(OnComplete, OnError, OnNext)) 86 | import RxJS.Observable (Observable) 87 | import RxJS.Subscriber (Subscriber) 88 | import RxJS.Subscription (Subscription) 89 | 90 | 91 | -- | Please see [RxJS Version 5.* documentation](http://reactivex.io/rxjs/) for 92 | -- | additional details on proper usage of the library. 93 | 94 | foreign import data ReplaySubject :: Type -> Type 95 | 96 | instance functorReplaySubject :: Functor ReplaySubject where 97 | map = _map 98 | 99 | instance applyReplaySubject :: Apply ReplaySubject where 100 | apply = combineLatest id 101 | 102 | instance applicativeReplaySubject :: Applicative ReplaySubject where 103 | pure = just 104 | 105 | instance bindReplaySubject :: Bind ReplaySubject where 106 | bind = mergeMap 107 | 108 | instance monadReplaySubject :: Monad ReplaySubject 109 | 110 | -- | NOTE: The semigroup instance uses `merge` NOT `concat`. 111 | instance semigroupReplaySubject :: Semigroup (ReplaySubject a) where 112 | append = merge 113 | 114 | instance altReplaySubject :: Alt ReplaySubject where 115 | alt = merge 116 | 117 | instance plusReplaySubject :: Plus ReplaySubject where 118 | empty = _empty unit 119 | 120 | instance alternativeReplaySubject :: Alternative ReplaySubject 121 | 122 | instance monadZeroReplaySubject :: MonadZero ReplaySubject 123 | 124 | instance monadPlusReplaySubject :: MonadPlus ReplaySubject 125 | 126 | -- Scheduling 127 | 128 | -- | Makes every `next` call run in the new Scheduler. 129 | foreign import observeOn :: forall a. Scheduler -> ReplaySubject a -> ReplaySubject a 130 | 131 | -- | Makes subscription happen on a given Scheduler. 132 | foreign import subscribeOn :: forall a. Scheduler -> ReplaySubject a -> ReplaySubject a 133 | 134 | -- Subscription 135 | 136 | -- | Subscribing to an ReplaySubject is like calling a function, providing 137 | -- | `next`, `error` and `completed` effects to which the data will be delivered. 138 | foreign import subscribe :: forall a e. Subscriber a -> ReplaySubject a -> Eff (|e) Subscription 139 | 140 | foreign import subscribeObservableTo :: forall a e. Observable a -> ReplaySubject a -> Eff (|e) Subscription 141 | 142 | -- Subscribe to an ReplaySubject, supplying only the `next` function. 143 | foreign import subscribeNext 144 | :: forall a e. (a -> Eff (|e) Unit) 145 | -> ReplaySubject a 146 | -> Eff (|e) Subscription 147 | 148 | 149 | -- Creation Operator 150 | 151 | -- | Creates an ReplaySubject that emits the value specify, 152 | -- | and then emits a complete notification. An alias for `of`. 153 | foreign import just :: forall a. a -> ReplaySubject a 154 | 155 | foreign import _empty :: forall a. Unit -> ReplaySubject a 156 | 157 | -- ReplaySubject Operators 158 | 159 | -- | Send a new value to a ReplaySubject 160 | foreign import next :: forall a e. a -> ReplaySubject a -> Eff e Unit 161 | 162 | -- | An alias for next 163 | send :: forall a e. a -> ReplaySubject a -> Eff e Unit 164 | send = next 165 | 166 | -- | Create an Observable from a ReplaySubject 167 | foreign import asObservable :: forall a. ReplaySubject a -> Observable a 168 | 169 | 170 | -- Transformation Operators 171 | 172 | -- | Collects values from the first ReplaySubject into an Array, and emits that array only when 173 | -- | second ReplaySubject emits. 174 | foreign import buffer :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject (Array a) 175 | 176 | -- | Collects values from the past as an array, emits that array when 177 | -- | its size (arg1) reaches the specified buffer size, and starts a new buffer. 178 | -- | The new buffer starts with nth (arg2) element of the ReplaySubject counting 179 | -- | from the beginning of the *last* buffer. 180 | foreign import bufferCount :: forall a. Int -> Int -> ReplaySubject a -> ReplaySubject (Array a) 181 | 182 | -- | Collects values from the past as an array, and emits those arrays 183 | -- | periodically in time. The first argument is how long to fill the buffer. 184 | -- | The second argument is specifies when to open the next buffer following an 185 | -- | emission. The third argument is the maximum size of any buffer. 186 | bufferTime :: forall a. Int -> Int -> Int -> (ReplaySubject a) -> (ReplaySubject (Array a)) 187 | bufferTime = runFn4 bufferTimeImpl 188 | 189 | foreign import bufferTimeImpl :: forall a. Fn4 Int Int Int (ReplaySubject a) (ReplaySubject (Array a)) 190 | 191 | -- | Collects values from the source ReplaySubject (arg1) as an array. Starts collecting only when 192 | -- | the opening (arg2) ReplaySubject emits, and calls the closingSelector function (arg3) to get an ReplaySubject 193 | -- | that decides when to close the buffer. Another buffer opens when the 194 | -- | opening ReplaySubject emits its next value. 195 | bufferToggle 196 | :: forall a b c. (ReplaySubject a) 197 | -> (ReplaySubject b) 198 | -> (b -> ReplaySubject c) 199 | -> (ReplaySubject (Array a)) 200 | bufferToggle = runFn3 bufferToggleImpl 201 | 202 | 203 | foreign import bufferToggleImpl 204 | :: forall a b c. Fn3 (ReplaySubject a) (ReplaySubject b) (b -> ReplaySubject c) (ReplaySubject (Array a)) 205 | 206 | -- | Collects values from the past as an array. When it starts collecting values, 207 | -- | it calls a function that returns an ReplaySubject that emits to close the 208 | -- | buffer and restart collecting. 209 | foreign import bufferWhen :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject (Array a) 210 | 211 | -- | Equivalent to mergeMap (a.k.a, `>>=`) EXCEPT that, unlike mergeMap, 212 | -- | the next bind will not run until the ReplaySubject generated by the projection function (arg2) 213 | -- | completes. That is, composition is sequential, not concurrent. 214 | -- | Warning: if source values arrive endlessly and faster than their corresponding 215 | -- | inner ReplaySubjects can complete, it will result in memory issues as inner 216 | -- | ReplaySubjects amass in an unbounded buffer waiting for their turn to be subscribed to. 217 | foreign import concatMap :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject b 218 | 219 | -- | The type signature explains it best. Warning: Like `concatMap`, composition is sequential. 220 | foreign import concatMapTo 221 | :: forall a b c. ReplaySubject a -> ReplaySubject b -> (a -> b -> ReplaySubject c) -> ReplaySubject c 222 | 223 | -- | It's Like concatMap (a.k.a, `>>=`) EXCEPT that it ignores every new projected 224 | -- | ReplaySubject if the previous projected ReplaySubject has not yet completed. 225 | foreign import exhaustMap :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject b 226 | 227 | -- | It's similar to mergeMap, but applies the projection function to every source 228 | -- | value as well as every output value. It's recursive. 229 | foreign import expand :: forall a. ReplaySubject a -> (a -> ReplaySubject a) -> ReplaySubject a 230 | 231 | -- | Groups the items emitted by an ReplaySubject (arg2) according to the value 232 | -- | returned by the grouping function (arg1). Each group becomes its own 233 | -- | ReplaySubject. 234 | foreign import groupBy :: forall a b. (a -> b) -> ReplaySubject a -> ReplaySubject (ReplaySubject a) 235 | 236 | foreign import _map :: forall a b. (a -> b) -> ReplaySubject a -> ReplaySubject b 237 | 238 | -- | Emits the given constant value on the output ReplaySubject every time 239 | -- | the source ReplaySubject emits a value. 240 | foreign import mapTo :: forall a b. b -> ReplaySubject a -> ReplaySubject b 241 | 242 | -- | Maps each value to an ReplaySubject, then flattens all of these ReplaySubjects 243 | -- | using mergeAll. It's just monadic `bind`. 244 | foreign import mergeMap :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject b 245 | 246 | -- | Maps each value of the ReplaySubject (arg1) to the same inner ReplaySubject (arg2), 247 | -- | then flattens the result. 248 | foreign import mergeMapTo :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject b 249 | 250 | -- | Puts the current value and previous value together as an array, and emits that. 251 | foreign import pairwise :: forall a. ReplaySubject a -> ReplaySubject (Array a) 252 | 253 | -- | Given a predicate function (arg1), and an ReplaySubject (arg2), it outputs a 254 | -- | two element array of partitioned values 255 | -- | (i.e., [ ReplaySubject valuesThatPassPredicate, ReplaySubject valuesThatFailPredicate ]). 256 | foreign import partition :: forall a. (a -> Boolean) -> ReplaySubject a -> Array (ReplaySubject a) 257 | 258 | -- | Given an accumulator function (arg1), an initial value (arg2), and 259 | -- | a source ReplaySubject (arg3), it returns an ReplaySubject that emits the current 260 | -- | accumlation whenever the source emits a value. 261 | foreign import scan :: forall a b. (a -> b -> b) -> b -> ReplaySubject a -> ReplaySubject b 262 | 263 | -- | Projects each source value to an ReplaySubject which is merged in the output 264 | -- | ReplaySubject, emitting values only from the most recently projected ReplaySubject. 265 | foreign import switchMap :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject b 266 | 267 | -- | It's like switchMap, but maps each value to the same inner ReplaySubject. 268 | foreign import switchMapTo :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject b 269 | 270 | -- | It's like buffer, but emits a nested ReplaySubject instead of an array. 271 | foreign import window :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject (ReplaySubject a) 272 | 273 | -- | It's like bufferCount, but emits a nested ReplaySubject instead of an array. 274 | foreign import windowCount :: forall a. Int -> Int -> ReplaySubject a -> ReplaySubject (ReplaySubject a) 275 | 276 | -- | It's like bufferTime, but emits a nested ReplaySubject instead of an array, 277 | -- | and it doesn't take a maximum size parameter. arg1 is how long to 278 | -- | buffer items into a new ReplaySubject, arg2 is the when the next buffer should begin, 279 | -- | and arg3 is the source ReplaySubject. 280 | foreign import windowTime :: forall a. Int -> Int -> ReplaySubject a -> ReplaySubject (ReplaySubject a) 281 | 282 | -- | It's like bufferToggle, but emits a nested ReplaySubject instead of an array. 283 | windowToggle 284 | :: forall a b c. (ReplaySubject a) 285 | -> (ReplaySubject b) 286 | -> (b -> ReplaySubject c) 287 | -> (ReplaySubject (Array a)) 288 | windowToggle = runFn3 windowToggleImpl 289 | 290 | foreign import windowToggleImpl 291 | :: forall a b c. Fn3 (ReplaySubject a) (ReplaySubject b) (b -> ReplaySubject c) (ReplaySubject (Array a)) 292 | 293 | -- | It's like bufferWhen, but emits a nested ReplaySubject instead of an array. 294 | foreign import windowWhen :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject (ReplaySubject a) 295 | 296 | -- Filtering Operators 297 | 298 | -- | It's like auditTime, but the silencing duration is determined by a second ReplaySubject. 299 | foreign import audit :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject a 300 | 301 | -- | Ignores source values for duration milliseconds, 302 | -- | then emits the most recent value from the source ReplaySubject, then repeats this process. 303 | foreign import auditTime :: forall a. Int -> ReplaySubject a -> ReplaySubject a 304 | 305 | -- | It's like debounceTime, but the time span of emission silence is determined 306 | -- | by a second ReplaySubject. Allows for a variable debounce rate. 307 | foreign import debounce :: forall a. ReplaySubject a -> (a -> ReplaySubject Int) -> ReplaySubject a 308 | 309 | -- | It's like delay, but passes only the most recent value from each burst of emissions. 310 | foreign import debounceTime :: forall a. Int -> ReplaySubject a -> ReplaySubject a 311 | 312 | -- | Returns an ReplaySubject that emits all items emitted by the source ReplaySubject 313 | -- | that are distinct by comparison from previous items. 314 | foreign import distinct :: forall a. ReplaySubject a -> ReplaySubject a 315 | 316 | -- | Returns an ReplaySubject that emits all items emitted by the source ReplaySubject 317 | -- | that are distinct by comparison from the previous item. 318 | foreign import distinctUntilChanged :: forall a. ReplaySubject a -> ReplaySubject a 319 | 320 | -- | Emits the single value at the specified index in a sequence of emissions 321 | -- | from the source ReplaySubject. 322 | foreign import elementAt :: forall a. ReplaySubject a -> Int -> ReplaySubject a 323 | 324 | -- | Filter items emitted by the source ReplaySubject by only emitting those that 325 | -- | satisfy a specified predicate. 326 | foreign import filter :: forall a. (a -> Boolean) -> ReplaySubject a -> ReplaySubject a 327 | 328 | -- | Ignores all items emitted by the source ReplaySubject and only passes calls of complete or error. 329 | foreign import ignoreElements :: forall a. ReplaySubject a -> ReplaySubject a 330 | 331 | -- | Returns an ReplaySubject that emits only the last item emitted by the source ReplaySubject. 332 | foreign import last :: forall a. ReplaySubject a -> ReplaySubject a 333 | 334 | -- | It's like sampleTime, but samples whenever the notifier ReplaySubject emits something. 335 | foreign import sample :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject a 336 | 337 | -- | Periodically looks at the source ReplaySubject and emits whichever 338 | -- | value it has most recently emitted since the previous sampling, unless the source has not emitted anything since the previous sampling. 339 | foreign import sampleTime :: forall a. Int -> ReplaySubject a -> ReplaySubject a 340 | 341 | -- | Returns an ReplaySubject that skips n items emitted by an ReplaySubject. 342 | foreign import skip :: forall a. Int -> ReplaySubject a -> ReplaySubject a 343 | 344 | -- | Returns an ReplaySubject that skips items emitted by the source ReplaySubject until a second ReplaySubject emits an item. 345 | foreign import skipUntil :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject a 346 | 347 | -- | Returns an ReplaySubject that skips all items emitted 348 | -- | by the source ReplaySubject as long as a specified condition holds true, 349 | -- | but emits all further source items as soon as the condition becomes false. 350 | foreign import skipWhile :: forall a. (a -> Boolean) -> ReplaySubject a -> ReplaySubject a 351 | 352 | -- | Emits only the first n values emitted by the source ReplaySubject. 353 | foreign import take :: forall a. Int -> ReplaySubject a -> ReplaySubject a 354 | 355 | -- | Lets values pass until a second ReplaySubject emits something. Then, it completes. 356 | foreign import takeUntil :: forall a b. ReplaySubject a -> ReplaySubject b -> ReplaySubject a 357 | 358 | -- | Emits values emitted by the source ReplaySubject so long as each value satisfies 359 | -- | the given predicate, and then completes as soon as this predicate is not satisfied. 360 | foreign import takeWhile :: forall a. (a -> Boolean) -> ReplaySubject a -> ReplaySubject a 361 | 362 | -- | It's like throttleTime, but the silencing duration is determined by a second ReplaySubject. 363 | foreign import throttle :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject a 364 | 365 | -- | Emits a value from the source ReplaySubject, then ignores subsequent source values 366 | -- | for duration milliseconds, then repeats this process. 367 | foreign import throttleTime :: forall a. Int -> ReplaySubject a -> ReplaySubject a 368 | 369 | 370 | -- Combination Operators 371 | 372 | -- | An ReplaySubject of projected values from the most recent values from each input ReplaySubject. 373 | foreign import combineLatest 374 | :: forall a b c. (a -> b -> c) -> ReplaySubject a -> ReplaySubject b -> ReplaySubject c 375 | 376 | -- | Concatenates two ReplaySubjects together by sequentially emitting their values, one ReplaySubject after the other. 377 | foreign import concat :: forall a. ReplaySubject a -> ReplaySubject a -> ReplaySubject a 378 | 379 | -- | Converts a higher-order ReplaySubject into a first-order ReplaySubject by concatenating the inner ReplaySubjects in order. 380 | foreign import concatAll :: forall a. ReplaySubject (ReplaySubject a) -> ReplaySubject a 381 | 382 | -- | Flattens an ReplaySubject-of-ReplaySubjects by dropping the next inner ReplaySubjects 383 | -- | while the current inner is still executing. 384 | foreign import exhaust :: forall a. ReplaySubject (ReplaySubject a) -> ReplaySubject a 385 | 386 | -- | Creates an output ReplaySubject which concurrently emits all values from each input ReplaySubject. 387 | foreign import merge :: forall a. ReplaySubject a -> ReplaySubject a -> ReplaySubject a 388 | 389 | -- | Converts a higher-order ReplaySubject into a first-order ReplaySubject 390 | -- | which concurrently delivers all values that are emitted on the inner ReplaySubjects. 391 | foreign import mergeAll :: forall a. ReplaySubject (ReplaySubject a) -> ReplaySubject a 392 | 393 | -- | Returns an ReplaySubject that mirrors the first source ReplaySubject to emit an 394 | -- | item from the array of ReplaySubjects. 395 | foreign import race :: forall a. Array (ReplaySubject a) -> ReplaySubject a 396 | 397 | -- | Returns an ReplaySubject that emits the items in the given Array before 398 | -- | it begins to emit items emitted by the source ReplaySubject. 399 | foreign import startWith :: forall a. Array a -> ReplaySubject a -> ReplaySubject a 400 | 401 | -- | Combines each value from the source ReplaySubjects using a project function to 402 | -- | determine the value to be emitted on the output ReplaySubject. 403 | foreign import withLatestFrom 404 | :: forall a b c. (a -> b -> c) -> ReplaySubject a -> ReplaySubject b -> ReplaySubject c 405 | 406 | -- | Waits for each ReplaySubject to emit a value. Once this occurs, all values 407 | -- | with the corresponding index will be emitted. This will continue until at 408 | -- | least one inner ReplaySubject completes. 409 | foreign import zip :: forall a. Array (ReplaySubject a) -> ReplaySubject (Array a) 410 | 411 | -- Error Handling Operators 412 | 413 | foreign import catch :: forall a. (ReplaySubject a) -> (Error -> ReplaySubject a) -> (ReplaySubject a) 414 | 415 | -- | If the source ReplaySubject calls error, this method will resubscribe to the 416 | -- | source ReplaySubject n times rather than propagating the error call. 417 | foreign import retry :: forall a. Int -> ReplaySubject a -> ReplaySubject a 418 | 419 | -- Utility Operators 420 | 421 | -- | Time shifts each item by some specified amount of milliseconds. 422 | foreign import delay :: forall a. Int -> ReplaySubject a -> ReplaySubject a 423 | 424 | -- | Delays the emission of items from the source ReplaySubject by a given time 425 | -- | span determined by the emissions of another ReplaySubject. 426 | foreign import delayWhen :: forall a b. ReplaySubject a -> (a -> ReplaySubject b) -> ReplaySubject a 427 | 428 | foreign import dematerialize :: forall a. ReplaySubject (Notification a) -> ReplaySubject a 429 | 430 | foreign import _materialize 431 | :: forall a. 432 | Fn4 433 | (ReplaySubject a) 434 | (a -> Notification a) 435 | (Error -> Notification a) 436 | (Notification a) 437 | (ReplaySubject (Notification a)) 438 | 439 | materialize :: forall a. ReplaySubject a -> ReplaySubject (Notification a) 440 | materialize ob = runFn4 _materialize ob OnNext OnError OnComplete 441 | -- | Performs the effect on each value of the ReplaySubject. An alias for `do`. 442 | -- | Useful for testing (transparently performing an effect outside of a subscription). 443 | 444 | foreign import performEach :: forall a e. ReplaySubject a -> (a -> Eff (|e) Unit) -> Eff (|e) (ReplaySubject a) 445 | 446 | foreign import toArray :: forall a. ReplaySubject a -> ReplaySubject (Array a) 447 | 448 | -- | Returns a ReplaySubject that emits the items emitted by the source ReplaySubject or a specified default item 449 | -- | if the source ReplaySubject is empty. 450 | -- | 451 | -- | ![marble diagram](http://reactivex.io/documentation/operators/images/defaultIfEmpty.c.png) 452 | -- | 453 | -- | takes a defaultValue which is the item to emit if the source ReplaySubject emits no items. 454 | -- | 455 | -- | returns a ReplaySubject that emits either the specified default item if the source ReplaySubject emits no 456 | -- | items, or the items emitted by the source ReplaySubject 457 | foreign import defaultIfEmpty :: forall a. ReplaySubject a -> a -> ReplaySubject a 458 | 459 | -- | Determines whether all elements of a ReplaySubject satisfy a condition. 460 | -- | Returns a ReplaySubject containing a single element determining whether all 461 | -- | elements in the source ReplaySubject pass the test in the specified predicate. 462 | foreign import every :: forall a. ReplaySubject a -> (a -> Boolean) -> ReplaySubject Boolean 463 | 464 | -- | Tests whether this `ReplaySubject` emits no elements. 465 | -- | 466 | -- | returns a ReplaySubject emitting one single Boolean, which is `true` if this `ReplaySubject` 467 | -- | emits no elements, and `false` otherwise. 468 | foreign import isEmpty :: forall a. ReplaySubject a -> ReplaySubject Boolean 469 | 470 | -- | Returns a ReplaySubject that emits only the first item emitted by the source 471 | -- | ReplaySubject that satisfies the given predicate. 472 | foreign import first :: forall a. ReplaySubject a -> (a -> Boolean) -> ReplaySubject a 473 | 474 | -- Aggregate Operators 475 | 476 | -- | Counts the number of emissions on the source and emits that number when the source completes. 477 | foreign import count :: forall a. ReplaySubject a -> ReplaySubject Int 478 | 479 | -- | Applies an accumulator function over the source, and returns the accumulated 480 | -- | result when the source completes, given a seed value. 481 | foreign import reduce :: forall a b. (a -> b -> b) -> b -> ReplaySubject a -> ReplaySubject b 482 | 483 | -- Helper Functions 484 | 485 | -- | Run a source's effects 486 | foreign import unwrap :: forall a e. ReplaySubject (Eff e a) -> Eff e (ReplaySubject a) 487 | -------------------------------------------------------------------------------- /src/RxJS/Scheduler.js: -------------------------------------------------------------------------------- 1 | /* global exports */ 2 | "use strict"; 3 | 4 | // module RxJS.Scheduler 5 | 6 | var Rx = require('rxjs'); 7 | 8 | exports.queue = Rx.Scheduler.queue; 9 | exports.asap = Rx.Scheduler.asap; 10 | exports.async = Rx.Scheduler.async; 11 | exports.animationFrame = Rx.Scheduler.animationFrame; 12 | -------------------------------------------------------------------------------- /src/RxJS/Scheduler.purs: -------------------------------------------------------------------------------- 1 | module RxJS.Scheduler 2 | ( Scheduler(..) 3 | , queue 4 | , asap 5 | , async 6 | , animationFrame 7 | ) 8 | where 9 | 10 | -- | Please see [RxJS Version 5.* documentation](http://reactivex.io/rxjs/) for 11 | -- | additional details on proper usage of the library. 12 | 13 | foreign import data Scheduler :: Type 14 | 15 | foreign import queue :: Scheduler 16 | 17 | foreign import asap :: Scheduler 18 | 19 | foreign import async :: Scheduler 20 | 21 | foreign import animationFrame :: Scheduler 22 | -------------------------------------------------------------------------------- /src/RxJS/Subscriber.purs: -------------------------------------------------------------------------------- 1 | module RxJS.Subscriber 2 | (Subscriber) 3 | where 4 | 5 | import Prelude (Unit) 6 | import Control.Monad.Eff (Eff) 7 | import Control.Monad.Eff.Exception (Error) 8 | 9 | type Subscriber a 10 | = { next :: forall e. a -> Eff e Unit 11 | , error :: forall e. Error -> Eff e Unit 12 | , completed :: forall e. Unit -> Eff e Unit 13 | } 14 | -------------------------------------------------------------------------------- /src/RxJS/Subscription.js: -------------------------------------------------------------------------------- 1 | /* global exports */ 2 | "use strict"; 3 | 4 | // module RxJS.Subscription 5 | 6 | var Rx = require('rxjs'); 7 | 8 | exports.unsubscribe = function(sub){ 9 | return function(){ 10 | sub.unsubscribe(); 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /src/RxJS/Subscription.purs: -------------------------------------------------------------------------------- 1 | module RxJS.Subscription 2 | ( Subscription(..) 3 | , unsubscribe 4 | ) where 5 | 6 | import Prelude (Unit) 7 | import Control.Monad.Eff (Eff) 8 | 9 | -- | When you subscribe, you get back a Subscription, which represents the 10 | -- | ongoing execution. 11 | foreign import data Subscription :: Type 12 | 13 | -- | Call unsubscribe() to cancel the execution. 14 | foreign import unsubscribe :: forall e. Subscription -> Eff e Unit 15 | -------------------------------------------------------------------------------- /src/entry.js: -------------------------------------------------------------------------------- 1 | var myMain = require('./Main.purs'); 2 | 3 | myMain.main(); 4 | -------------------------------------------------------------------------------- /test/Main.purs: -------------------------------------------------------------------------------- 1 | module Test.Main where 2 | 3 | import RxJS.Observable 4 | import Prelude (Unit, bind, const, map, pure, unit, (#), (+), (<), (>), discard) 5 | import Control.Monad.Aff.AVar (AVAR) 6 | import Control.Monad.Eff (Eff) 7 | import Control.Monad.Eff.Class (liftEff) 8 | import Control.Monad.Eff.Console (CONSOLE) 9 | import Control.MonadPlus (empty) 10 | import Data.String (length) 11 | import Test.Unit (suite, test) 12 | import Test.Unit.Console (TESTOUTPUT) 13 | import Test.Unit.Main (exit, runTest) 14 | 15 | main :: forall e. Eff (console :: CONSOLE, testOutput :: TESTOUTPUT, avar :: AVAR | e) Unit 16 | main = do 17 | runTest do 18 | suite "observable creation methods" do 19 | test "interval" do 20 | liftEff ((interval 200 # take 2) # subObservable) 21 | test "timer" do 22 | liftEff ((timer 200 100 # take 2) # subObservable) 23 | test "never" do 24 | liftEff ((never) # subObservable) 25 | test "empty" do 26 | liftEff ((empty) # subObservable) 27 | test "range" do 28 | liftEff ((range 0 5) # subObservable) 29 | test "fromArray" do 30 | liftEff ((fromArray [1,2,3,4,5]) # subObservable) 31 | test "just" do 32 | liftEff ((just "Hello World!") # subObservable) 33 | suite "observable operators" do 34 | test "audit" do 35 | liftEff ((audit observable (\x -> observable3)) # subObservable) 36 | test "auditTime" do 37 | liftEff ((auditTime 200 observable) # subObservable) 38 | test "bufferCount" do 39 | liftEff ((bufferCount 2 1 observable) # subObservable) 40 | test "combineLatest" do 41 | liftEff ((combineLatest (\acc cur -> acc) observable observable2) # subObservable) 42 | test "concat" do 43 | liftEff ((concat observable observable3) # subObservable) 44 | test "concatAll" do 45 | liftEff ((concatAll higherOrder) # subObservable) 46 | test "concatMap" do 47 | liftEff ((concatMap observable (\n -> just n)) # subObservable) 48 | test "count" do 49 | liftEff ((count observable) # subObservable) 50 | test "debounce" do 51 | liftEff ((debounce observable3 (\x -> observable)) # subObservable) 52 | test "debounceTime" do 53 | liftEff ((debounceTime 1000 observable) # subObservable) 54 | test "defaultIfEmpty" do 55 | liftEff ((defaultIfEmpty observable 0) # subObservable) 56 | test "delay" do 57 | liftEff ((delay 200 observable) # subObservable) 58 | test "delayWhen" do 59 | liftEff ((delayWhen observable (\x -> observable2)) # subObservable) 60 | test "distinct" do 61 | liftEff ((distinct observable) # subObservable) 62 | test "distinctUntilChanged" do 63 | liftEff ((distinctUntilChanged observable) # subObservable) 64 | test "exhaust" do 65 | liftEff ((exhaust higherOrder) # subObservable) 66 | test "exhaustMap" do 67 | liftEff ((exhaustMap observable (\x -> observable3)) # subObservable) 68 | test "elementAt" do 69 | liftEff ((elementAt observable 2) # subObservable) 70 | test "expand" do 71 | liftEff ((expand observable (\x -> if (x < 3) then just (x + 1) else empty)) # subObservable) 72 | test "every" do 73 | liftEff ((every observable (_ > 3) # subObservable)) 74 | test "filter" do 75 | liftEff ((filter (_ > 2) observable) # subObservable) 76 | test "groupBy" do 77 | liftEff ((groupBy length observable2) # subObservable) 78 | test "ignoreElements" do 79 | liftEff ((ignoreElements observable) # subObservable) 80 | test "isEmpty" do 81 | liftEff ((isEmpty observable) # subObservable) 82 | test "first" do 83 | liftEff ((first observable (const true) # subObservable)) 84 | test "last" do 85 | liftEff ((last observable (const true) # subObservable)) 86 | test "map" do 87 | liftEff ((map length observable2) # subObservable) 88 | test "mapTo" do 89 | liftEff ((mapTo "A" observable) # subObservable) 90 | test "merge" do 91 | liftEff ((merge observable observable3) # subObservable) 92 | test "mergeAll" do 93 | liftEff ((mergeAll higherOrder) # subObservable) 94 | test "mergeMap" do 95 | liftEff ((mergeMap observable (\a -> observable3)) # subObservable) 96 | test "mergeMapTo" do 97 | liftEff ((mergeMapTo observable observable3) # subObservable) 98 | test "race" do 99 | liftEff ((race [observable, observable3]) # subObservable) 100 | test "reduce" do 101 | liftEff ((reduce (\acc cur -> acc) 0 observable) # subObservable) 102 | test "scan" do 103 | liftEff ((scan (\acc cur -> acc) 0 observable) # subObservable) 104 | test "retry" do 105 | liftEff ((retry 10 observable) # subObservable) 106 | test "sample" do 107 | liftEff ((sample observable observable2) # subObservable) 108 | test "sampleTime" do 109 | liftEff ((sampleTime 1000 observable) # subObservable) 110 | test "share" do 111 | liftEff ((share observable) # subObservable) 112 | test "skip" do 113 | liftEff ((skip 2 observable) # subObservable) 114 | test "skipUntil" do 115 | liftEff ((skipUntil observable observable2) # subObservable) 116 | test "skipWhile" do 117 | liftEff ((skipWhile (_ < 2) observable) # subObservable) 118 | test "startWith" do 119 | liftEff ((startWith 0 observable) # subObservable) 120 | test "switchMap" do 121 | liftEff ((switchMap observable (\x -> observable2)) # subObservable) 122 | test "switchMapTo" do 123 | liftEff ((switchMapTo observable2 observable) # subObservable) 124 | test "take" do 125 | liftEff ((take 3 observable) # subObservable) 126 | test "takeWhile" do 127 | liftEff ((takeWhile (_ < 4) observable) # subObservable) 128 | test "takeUntil" do 129 | liftEff ((takeUntil observable observable3) # subObservable) 130 | test "throttle" do 131 | liftEff ((throttle observable (\x -> observable3)) # subObservable) 132 | test "throttleTime" do 133 | liftEff ((throttleTime 200 observable) # subObservable) 134 | test "window" do 135 | liftEff ((window observable observable2) # subObservable) 136 | test "windowCount" do 137 | liftEff ((windowCount 1 1 observable) # subObservable) 138 | test "windowTime" do 139 | liftEff ((windowTime 100 100 observable) # subObservable) 140 | test "windowWhen" do 141 | liftEff ((windowWhen observable3 observable) # subObservable) 142 | test "windowToggle" do 143 | liftEff ((windowToggle observable observable2 (\x -> observable3)) # subObservable) 144 | test "withLatestFrom" do 145 | liftEff ((withLatestFrom (\a b -> a) observable observable2) # subObservable) 146 | test "zip" do 147 | liftEff ((zip [observable, observable3]) # subObservable) 148 | (exit 0) 149 | 150 | 151 | observable :: Observable Int 152 | observable = fromArray [1,2,3,4,5,6] 153 | 154 | observable2 :: Observable String 155 | observable2 = fromArray ["h","e","ll","o"] 156 | 157 | observable3 :: Observable Int 158 | observable3 = fromArray [6,5,4,3,2,1] 159 | 160 | higherOrder :: Observable (Observable String) 161 | higherOrder = just observable2 162 | 163 | subObservable :: forall a e. Observable a -> Eff e Unit 164 | subObservable obs = do 165 | sub <- obs # subscribeNext noop 166 | pure unit 167 | 168 | noop :: forall a e. a -> Eff e Unit 169 | noop a = pure unit 170 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // var PurescriptWebpackPlugin = require('purescript-webpack-plugin'); 4 | 5 | var src = ['bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs']; 6 | 7 | 8 | 9 | var modulesDirectories = [ 10 | 'node_modules', 11 | 'bower_components' 12 | ]; 13 | 14 | var config 15 | = { entry: './src/entry' 16 | , output: { 17 | filename: 'app.js' 18 | } 19 | , bundle: true 20 | , module: { loaders: [ { test: /\.purs$/ 21 | , loader: 'purs-loader' 22 | } ] } 23 | , resolve: { modulesDirectories: modulesDirectories, extensions: [ '', '.js', '.purs'] } 24 | 25 | , devServer: { historyApiFallback: false, 26 | headers: { "Access-Control-Allow-Origin": "*" } 27 | } 28 | } 29 | ; 30 | 31 | module.exports = config; 32 | --------------------------------------------------------------------------------