Re: [elm-discuss] Re: Implementing a protocol on top of WebSocket: should I build a effect module ?

2017-05-17 Thread Christophe de Vienne


Le 17/05/2017 à 09:15, Christophe de Vienne a écrit :
> 
> 
> Le 17/05/2017 à 08:24, Wojciech Piekutowski a écrit :
>> There's also https://github.com/fbonetti/elm-phoenix-socket/. It doesn't
>> use an effect manager, but apparently  because of that doesn't notify
>> about disconnection.
>>
> 
> Very interesting. One limit I see is that only one type of Msg can be
> emitted by the subscription, which forces to handle all the
> subscriptions in the same component.
> 
> In my case, I need the subscriptions to be initialized and used in
> various components. I think I found a way to do that, I will put it on
> github soon.
> 
> Another limit I an hitting with a non-effect module, and for which I see
> no solution, is when several messages arrive in a single websocket
> message. In this case we should emit several custom message for one
> incoming websocket message.
> 
> Fortunalely, I can temper with the server and make sure one nats message
> comes in as a single websocket message, which workaround the issue.
> 

So, I have a first version of a Nats module, which handles properly the
subscriptions (at least as I wanted it to).

https://github.com/orus-io/elm-nats

It is requires a nats/websocket gateway I wrote too
(https://github.com/orus-io/nats-websocket-gw)

The main thing that bothers me is that I will need to pass the
Nats.State to every update function because subscribing requires an
update of the state... And I see no way to avoid that except using an
effect module.

There are plenty improvements to do (starting with the documentation),
but some feedback would be really appreciated.

Thanks for all the helpfull response to my OP !

-- 
Christophe de Vienne

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: What heap implementations exist for Elm?

2017-05-17 Thread 'Rupert Smith' via Elm Discuss
On Wednesday, May 17, 2017 at 3:57:44 PM UTC+1, Rupert Smith wrote:
>
> On Wednesday, May 17, 2017 at 11:40:35 AM UTC+1, Rupert Smith wrote:
>>
>> http://package.elm-lang.org/packages/TSFoster/elm-heap/latest
>>
>
> Bugger. This heap implementation does not allow and arbitrary comparison 
> function. It has this:
>
>  by : (a -> comparable) -> Options b -> Options a
>
> But that requires a mapping from the type being compares onto comparable.
>
> If there is an implementation that lets me use a comparison function of 
> type 'a -> a -> Order', that would be better.
>

But internally it does use an 'a -> a -> Order':

type Options a
= Options
{ order : SortOrder
, compare : a -> a -> Order
}

Which it builds by converting an 'a -> comparable' function:

makeCompare : (a -> comparable) -> (a -> a -> Order)
makeCompare fn a b =
Basics.compare (fn a) (fn b)

Perhaps the author meant to expose Options(..) so users can build their own 
compare function?

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: What heap implementations exist for Elm?

2017-05-17 Thread 'Rupert Smith' via Elm Discuss
On Wednesday, May 17, 2017 at 11:40:35 AM UTC+1, Rupert Smith wrote:
>
> http://package.elm-lang.org/packages/TSFoster/elm-heap/latest
>

Bugger. This heap implementation does not allow and arbitrary comparison 
function. It has this:

 by : (a -> comparable) -> Options b -> Options a

But that requires a mapping from the type being compares onto comparable.

If there is an implementation that lets me use a comparison function of 
type 'a -> a -> Order', that would be better.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] What heap implementations exist for Elm?

2017-05-17 Thread 'Rupert Smith' via Elm Discuss
I need a heap where I can supply my own ordering function:

ordering : a -> a -> Order

And be able to take the smallest item from the heap:

Heap.least : Heap a -> a

There is this one:

http://package.elm-lang.org/packages/TSFoster/elm-heap/latest

Any others?

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: Implementing a protocol on top of WebSocket: should I build a effect module ?

2017-05-17 Thread Christophe de Vienne
A nice place to start with if I want to go down the effect-module road.
Although as Mark said it rely on the WebSocket.LowLevel module, which
imply extra complexity in the implementation.

The resulting API looks a lot clearer and more natural than the other
phoenix implementation, which is a big bonus.

Le 17/05/2017 à 01:38, Oliver Searle-Barnes a écrit :
> You might find https://github.com/saschatimme/elm-phoenix useful to look
> at, it's an effects manager phoenix channels built on top of the
> websocket effects manager.
> 
> On Tuesday, 16 May 2017 15:30:18 UTC+1, Christophe de Vienne wrote:
> 
> Hi everyone,
> 
> I am attempting to implement the pub/sub NATS (https://nats.io)
> protocol
> on top of the WebSocket API as a TEA component.
> 
> I have a hard time finding an API for subscriptions: for each
> subscription some context must be kept, a unique subscription ID
> generated and in some case a unique reply subject too, and I would like
> each subscription to generate custom messages for the component which
> made it.
> 
> I suspect it would be a lot more natural with an effect module, with
> which I could (hopefully) write, in any part of the application:
> 
> subscriptions : Model -> Sub Msg
> subscriptions model =
> Nats.Subscribe model.endpoint "some.subject" MyMessage
> 
> or, for req/rep (a pub + a short-living sub expecting a result):
> 
> myrequest : Model -> Cmd Msg
> myrequest model =
> Nats.request model.endpoint "a.request.subject" MyReply
> 
> 
> Another difficulty I have is that in some cases I need to send 2 or 3
> messages through the websocket, in the right order, but WebSocket.send
> returns a Cmd. So I have to concat the 3 commands in 1 message, which
> works but oblige
> 
> Am I wrong being tempted by using an effect module for this kind of
> module ?
> If so how can I mimick such an API with a TEA approach  ?
> If not is there any documentation I can read to get familiar with
> them ?
> 
> Is there any existing module that does this kind of thing for another
> protocol ?
> 
> Thanks!
> 
> -- 
> Christophe de Vienne
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to elm-discuss+unsubscr...@googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.

-- 
Christophe de Vienne

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Re: Implementing a protocol on top of WebSocket: should I build a effect module ?

2017-05-17 Thread Christophe de Vienne


Le 17/05/2017 à 08:24, Wojciech Piekutowski a écrit :
> There's also https://github.com/fbonetti/elm-phoenix-socket/. It doesn't
> use an effect manager, but apparently  because of that doesn't notify
> about disconnection.
> 

Very interesting. One limit I see is that only one type of Msg can be
emitted by the subscription, which forces to handle all the
subscriptions in the same component.

In my case, I need the subscriptions to be initialized and used in
various components. I think I found a way to do that, I will put it on
github soon.

Another limit I an hitting with a non-effect module, and for which I see
no solution, is when several messages arrive in a single websocket
message. In this case we should emit several custom message for one
incoming websocket message.

Fortunalely, I can temper with the server and make sure one nats message
comes in as a single websocket message, which workaround the issue.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.