| RxJs | @most/core | Remarks | Rx.NET |
|---|---|---|---|
| Creation | |||
from(px) |
fromPromise(px) |
:: Promise x → S x |
.ToObservable(), Observable.FromAsync |
of(x) |
now(x) |
:: x → S x |
Return(x) |
EMPTY or of() |
empty() |
EMPTY :: S *, empty :: () → S * |
Empty() |
throwError |
:: Error → S void |
Observable.Throw(ex) |
|
bindCallback((cb) => {})() |
never() |
:: () → S * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // :: ((l, r) -> s) -> [l, r] -> s | |
| const applyBin = | |
| <L, R, S>(fn: (l: L, r: R) => S) => | |
| ([l, r]: [L, R]): S => | |
| fn(l, r); | |
| // :: number -> (number, number) -> [number] | |
| const range = (step: number) => (start: number, stop: number) => | |
| Array.from( | |
| { length: Math.ceil((stop - start) / step) }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as M from '@most/core'; | |
| import { newDefaultScheduler } from '@most/scheduler'; | |
| import { pipe } from 'fp-ts/function'; | |
| import * as T from 'fp-ts/Task'; | |
| import * as A from 'fp-ts/Array'; | |
| import { o } from 'ramda'; | |
| import {last as lastM } from 'most-last'; | |
| import * as Rx from 'rxjs'; | |
| const taskReducer = <A>(acc: Promise<A[]>, ta: T.Task<A>) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import assert from 'node:assert/strict'; | |
| import { filter } from '../src/eventStream'; | |
| import { EventEmitter } from 'node:events'; | |
| describe("eventStream filter", function() { | |
| const | |
| passPattern = /^great/i, | |
| channelName = "landscape", | |
| filterGreatLandscapes = filter(channelName)((payload: string) => passPattern.test(payload)); |
An Applicative type (e.g. a Maybe) is also a Functor with an ap method. Thus, for the observations in the table it
can be used everywhere as an example.
| Purpose | Function | Signature | Example |
|---|---|---|---|
| swap types inside out | sequence(TypeRep f) |
t (f a) → f (t a)[^1] |
sequence(M)([Just(1)]) // -> Just [1] |
| apply effect + wrap inside out | traverse(TypeRep f) |
(a → f b) → t a → f (t b)[^1] |
traverse(M)(reciprocal, [2]) // -> Just [0.5] |
| swap data portion type inside out | lens(identity) |
Functor f ⇒ s → f s |
yLens(identity)({x: 1, y: M.Just(2)}) // -> Just {x:1,y:2} |
| apply effect to data portion + wrap inside out | lens |
Functor f ⇒ (a → f a) → s a → f (s a) |
yLens(reciprocal)({x: 1,y: 2}) // -> Just {x:1, y: 0.5} |
| Purpose | List | Object | Signature(s) |
|---|---|---|---|
| update/insert individual | update, assoc*, append, prepend |
assoc* |
Idx → a → {k: v} → {k: v} |
| insert range/collection | concat |
merge* |
[a] → [a] → [a];{k: v} → {k: v} → {k: v} |
| retrieve by key/index | nth, path, prop |
prop, path |
Idx → {a} → a |
| retrieve many by key/index | props |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Just my current implementation of Sam Miller's answer on Stack Overflow | |
| * @see https://stackoverflow.com/questions/7754695/boost-asio-async-write-how-to-not-interleaving-async-write-calls | |
| */ | |
| /* | |
| * File: NonInterleavingAsyncSocketWrite.hpp | |
| * Author: Matthias Seemann <seemann@visisoft.de> | |
| * @see https://stackoverflow.com/questions/7754695/boost-asio-async-write-how-to-not-interleaving-async-write-calls | |
| * | |
| * When using boost::asio::async_write: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <functional> | |
| #include <memory> | |
| #include <iterator> | |
| #include <algorithm> | |
| using namespace std; | |
| template<typename T> | |
| struct memfun_type |
NewerOlder