aleph

erik 2020-02-12T11:09:46.025800Z

I'm trying to create a stream from an existing stream xs in a way that put!s are automatically encoded to JSON and takes! decoded from JSON β€”Β it doesn't seem possible with the current API; should I just create two separate streams, one that is sink-only and another that is source-only?

erik 2020-02-12T11:10:03.026200Z

the question is about Manifold not Aleph, but I thought this would be the right place to ask nevertheless

mccraigmccraig 2020-02-12T11:35:30.027400Z

i don't know that you can do that @eallik - there's just the single xform on the stream constructor

mccraigmccraig 2020-02-12T11:36:03.027900Z

but why do you want to do that ? why not just put the object directly on the stream ?

erik 2020-02-12T11:36:41.028800Z

I have WS connections for exchanging messages in JSON format.

erik 2020-02-12T11:37:10.029500Z

I thought I'd just remove the hassle of json-> and ->json every time I take! from or put! to a connection

mccraigmccraig 2020-02-12T11:38:01.030200Z

(stream/transform (map json->) s)

mccraigmccraig 2020-02-12T11:38:16.030500Z

(stream/transform (map ->json) s)

erik 2020-02-12T11:38:32.031200Z

and then make one sink-only and the other source-only?

mccraigmccraig 2020-02-12T11:38:33.031300Z

will those not do the trick ?

mccraigmccraig 2020-02-12T11:43:44.031900Z

yes, use sink-only and source-only where it makes sense

erik 2020-02-12T11:44:47.032800Z

wait, transform returns a source, not a stream

erik 2020-02-12T11:45:08.033100Z

(stream/transform (map json->) s) makes sense but the other doesn't

mccraigmccraig 2020-02-12T11:46:15.034100Z

ah, ok - in which case does a plain (stream/map ->json s) do the trick for you ? iirc stream/map is very simply implemented with connect-via

erik 2020-02-12T11:48:35.035400Z

(defn convert-stream [f-src f-dst s]
  (let [src (s/map f-src s)
        sink (s/stream)]
    (s/connect-via sink #(s/put! s (f-dst %)) s)
    (s/splice sink src)))

erik 2020-02-12T11:48:59.035800Z

this is what I came up with. new to Manifold, making sure I got it right.

mccraigmccraig 2020-02-12T11:52:20.036Z

looks like it will work

mccraigmccraig 2020-02-12T11:52:45.036700Z

(without me doing any testing, anyway 😬)

erik 2020-02-12T21:19:59.039100Z

it worked when I changed to (s/connect-via sink #(s/put! s (f-src %)) s) β€” I got confused by the fact that messages should be delivered from the sink to the source, because on the outside, they are written to the sink and read from the source

erik 2020-02-12T21:20:50.039900Z

in fact, the names f-src and f-dst are confusion β€” they should instead be f-sink and f-source to indicate which one gets applied to which end of s

erik 2020-02-12T21:22:36.041100Z

also, it seems that it only makes sense to use my convert-stream over duplex streams, otherwise any value put! on the sink will be passed thru both functions

erik 2020-02-12T21:22:52.041300Z

does that make sense?