Re: [elm-discuss] Ports seem contrived when trying to format a value as money

2017-05-01 Thread Dwayne Crooks
No I haven't. Thanks for sharing. I'll keep an eye on it but I doubt I'd 
add it to the project.

On Sunday, April 30, 2017 at 9:03:09 PM UTC-4, Dustin Farris wrote:
>
> Also, have you seen elm-plot?
>
> https://terezka.github.io/elm-plot/
>
> I haven't played with it yet, but it looks pretty neat.  Might help with 
> some of your features that used highcharts?
>
> Dustin
>
>
> Sent from my iPhone
>
> On Apr 30, 2017, at 8:10 PM, Dwayne Crooks  > wrote:
>
> I posted here as the other thread seems to be closed off from replies.
>
> For this particular app I'm writing/porting the SPA from scratch to Elm 
> and the formatting issue was the first small hiccup I ran into. As 
> suggested in the other thread I went ahead and wrote the code I needed in 
> Elm.
>
> Here it is in case anyone else is interested:
>
> module Format exposing (asMoney)
>>
>> asMoney : Float -> String
>> asMoney value =
>> let
>> totalCents = round (value * 100)
>> dollars = totalCents // 100
>> cents = totalCents % 100
>> in
>> "$" ++ (groupBy 3 ',' dollars) ++ "." ++ (zeroPad 2 cents)
>>
>> groupBy : Int -> Char -> Int -> String
>> groupBy per sep n =
>> let
>> pow10 = 10 ^ per
>> in
>> if n < pow10 then
>> toString n
>> else
>> zeroPad 3 (n % pow10)
>> |> String.cons sep
>> |> String.append (groupBy per sep <| n // pow10)
>>
>> zeroPad : Int -> Int -> String
>> zeroPad k n = String.padLeft k '0' (toString n)
>
>
> *P.S.* *Dustin, I decided to write one for myself. But thanks.*
>
> My next task is to draw some charts using Highcharts. I expect ports would 
> be the approach here so I'm crossing my fingers and hoping it all works 
> out. I certainly won't want to be re-writing parts of Highcharts at this 
> point.
>
> -- 
> 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...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
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] Ports seem contrived when trying to format a value as money

2017-04-30 Thread Dwayne Crooks
I posted here as the other thread seems to be closed off from replies.

For this particular app I'm writing/porting the SPA from scratch to Elm and 
the formatting issue was the first small hiccup I ran into. As suggested in 
the other thread I went ahead and wrote the code I needed in Elm.

Here it is in case anyone else is interested:

module Format exposing (asMoney)
>
> asMoney : Float -> String
> asMoney value =
> let
> totalCents = round (value * 100)
> dollars = totalCents // 100
> cents = totalCents % 100
> in
> "$" ++ (groupBy 3 ',' dollars) ++ "." ++ (zeroPad 2 cents)
>
> groupBy : Int -> Char -> Int -> String
> groupBy per sep n =
> let
> pow10 = 10 ^ per
> in
> if n < pow10 then
> toString n
> else
> zeroPad 3 (n % pow10)
> |> String.cons sep
> |> String.append (groupBy per sep <| n // pow10)
>
> zeroPad : Int -> Int -> String
> zeroPad k n = String.padLeft k '0' (toString n)


*P.S.* *Dustin, I decided to write one for myself. But thanks.*

My next task is to draw some charts using Highcharts. I expect ports would 
be the approach here so I'm crossing my fingers and hoping it all works 
out. I certainly won't want to be re-writing parts of Highcharts at this 
point.

-- 
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] Ports seem contrived when trying to format a value as money

2017-04-30 Thread Dwayne Crooks
Let's keep the discussion civil guys. Overall, the consensus seems to be to 
re-implement it in Elm if my use case allows it. I'm cool with that as I'm 
actually only using the single argument version of *accounting.formatMoney*. 
Thanks to all who gave their honest opinion.

-- 
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] Ports seem contrived when trying to format a value as money

2017-04-30 Thread Dwayne Crooks
Thanks guys.

I explored Noah's approach to see how the solution would turn out. But I 
didn't like it. The code change required to format a list of floats as 
money is ridiculous. Here's what I started 
with 
https://gist.github.com/dwayne/550341a5b27ba3c03ce7eba92d33873d#file-0-start-elm.
 
And here's what I ended up 
with 
https://gist.github.com/dwayne/550341a5b27ba3c03ce7eba92d33873d#file-1a-useports-elm,
 
https://gist.github.com/dwayne/550341a5b27ba3c03ce7eba92d33873d#file-1b-useports-html.

*P.S.* *The solution still doesn't quite work because all money receives 
the first incoming subscription message causing them to display the same 
formatted value. I didn't bother to fix it because the solution is bad 
enough*.

I think we can safely rule out ports. Noah, do you have any thoughts on the 
code? Did I miss anything?

That leaves us with:

   1. Using a Native module. (Looks like the best compromise for my needs 
   in the short-term.)
   2. Rewrite in pure Elm. (Looks like the best long-term solution.)

Next step: I will write up a Native solution and see how that goes.

-- 
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] Ports seem contrived when trying to format a value as money

2017-04-29 Thread Dwayne Crooks
I'm porting an application from React/Redux to Elm and I'm having trouble 
figuring out how to format a value as money. In the original application we 
used http://openexchangerates.github.io/accounting.js/. So naturally I 
wanted to make use of that same library when writing the Elm version. Based 
on my reading ports seem to be the solution however when I think through 
the implications it doesn't seem natural to write my code in that way when 
formatting is a presentation concern.

Here's what I came up with:

1. I created a port module called Format.

port module Format exposing (..)
>
> port asMoney : Float -> Cmd msg
> port moneyFormats : (String -> msg) -> Sub msg


2. I originally envisioned writing the view as follows:

viewSales : Float -> Html Msg
> viewSales amount =
> viewWidget "Gross Sales (All Time)" (Format.asMoney amount)


But obviously, that's out the window since Format.asMoney returns a command.

3. It means I now have to format in my update function and store the 
formatted data in my model so that my view can access it. I find that very 
inconvenient and I don't want presentation concerns in neither my update 
function nor my model.

Am I thinking through this correctly?

How do I proceed?

Should I consider writing an external library with a Native module like for 
e.g. https://github.com/NoRedInk/elm-moment 
or https://github.com/evancz/elm-graphics?

Any help would be greatly appreciated.

-- 
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: Scaling Elm

2017-04-26 Thread Dwayne Crooks
How about writing an Elm front-end 
for https://github.com/gothinkster/realworld.

On Wednesday, April 19, 2017 at 5:11:05 AM UTC-4, Peter Damoc wrote:
>
> Hello community, 
>
> Scaling Elm apps seams to be a recurring topic. 
>
> I was wondering if maybe we could negotiate a minimal set of 
> functionality, something similar to ToDoMVC, that could be implemented 
> using different approaches to explore what could be the best way to 
> structure the code. 
>
> What should this minimal example cover and what this minimal example 
> should be (topic)?
>
> I'll start the list with some bits of functionality that I would like: 
>
> - multiple pages with common structure (sidebar/navbar)
> - navigation without reloading the app (SPA routing without the hash) 
> - authentication 
> - complex widget reuse (a module/widget that generates side-effects; e.g. 
> a weather widget, some stock ticker, an ad provided by a third party)
> - styling (CSS)
>
> I would also like the example to cover real world concerns of: 
> - using a build manager to integrate with other technologies 
> - development mode - deployment build
> - testing 
>
> As for topic, I was thinking about an interface to the MusicBrainz 
> Database (a simplified interface).
>
> What do you think? 
> What bits of functionality would you like to see exemplified? 
> Are you aware of any other project (in other languages) that exemplifies a 
> minimal set of functionality and could be used as a template?  
>
>
> -- 
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>

-- 
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] Unexpected parse error for reasonable code (Bug in parser?)

2017-04-25 Thread Dwayne Crooks
Thanks Dustin!

On Saturday, April 22, 2017 at 3:27:01 PM UTC-4, Dustin Farris wrote:
>
> This is because the syntax for record updates does not allow you to update 
> nested records like what you are attempting.
>
> This is part of an ongoing discussion.  There is a thread where you can 
> post your specific scenario: 
> https://groups.google.com/forum/#!searchin/elm-discuss/record%7Csort:relevance/elm-discuss/oWfARte8DJU/6eUvmL-jAwAJ
>
> Dustin
>
>
> On Apr 21, 2017, at 5:33 PM, Dwayne Crooks  > wrote:
>
> Hi,
>
> I got the following syntax error:
>
> I ran into something unexpected when parsing your code!
>> 62| { Rating.defaultViewConfig | readOnly = model.readOnly }
>>   ^
>> I am looking for one of the following things:
>> a closing bracket '}'
>> a lower case name
>> whitespace
>
>
> for the following snippet of code:
>
> view : Model -> Html Msg
>> view model =
>> let
>> ratingViewConfig =
>> { Rating.defaultViewConfig | readOnly = model.readOnly }
>> in
>> div []
>> [ Html.map SetRatingState <|
>> Rating.view ratingViewConfig model.ratingState
>> , label []
>> [ input
>> [ type_ "checkbox"
>> , checked model.readOnly
>> , onClick ToggleReadOnly
>> ]
>> []
>> , text "read only"
>> ]
>> ]
>
>
> If however I write the following:
>
> let
>> defaultViewConfig = Rating.defaultViewConfig
>> ratingViewConfig =
>> { defaultViewConfig | readOnly = model.readOnly }
>> in 
>
> ...
>
>
> Then everything works fine. Is this a bug in the parser?
>
> -- 
> 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...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
>
> -- 
> Dustin Farris
>
>
>
>

-- 
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: Unexpected error when parsing what seems to be reasonable code (Bug in parser maybe?)

2017-04-25 Thread Dwayne Crooks
Thanks guys! Both responses were helpful.

-- 
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] Unexpected error when parsing what seems to be reasonable code (Bug in parser maybe?)

2017-04-22 Thread Dwayne Crooks
Hi,

The following snippet of code:

view : Model -> Html Msg
> view model =
> let
> ratingViewConfig =
> { Rating.defaultViewConfig | readOnly = model.readOnly }
> in
> div []
> [ Html.map SetRatingState <|
> Rating.view ratingViewConfig model.ratingState
> , label []
> [ input
> [ type_ "checkbox"
> , checked model.readOnly
> , onClick ToggleReadOnly
> ]
> []
> , text "read only"
> ]
> ]


causes the following error to occur:

I ran into something unexpected when parsing your code!
> 63| { Rating.defaultViewConfig | readOnly = model.readOnly }
>   ^
> I am looking for one of the following things:
> a closing bracket '}'
> a lower case name
> whitespace


However, if I update the let bindings as follows:

let
> defaultViewConfig = Rating.defaultViewConfig
> ratingViewConfig =
> { defaultViewConfig | readOnly = model.readOnly }
> in
> ...


Then, there is no error. Am I missing something or is this a bug in the 
parser?

-- 
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] Unexpected parse error for reasonable code (Bug in parser?)

2017-04-22 Thread Dwayne Crooks
Hi,

I got the following syntax error:

I ran into something unexpected when parsing your code!
> 62| { Rating.defaultViewConfig | readOnly = model.readOnly }
>   ^
> I am looking for one of the following things:
> a closing bracket '}'
> a lower case name
> whitespace


for the following snippet of code:

view : Model -> Html Msg
> view model =
> let
> ratingViewConfig =
> { Rating.defaultViewConfig | readOnly = model.readOnly }
> in
> div []
> [ Html.map SetRatingState <|
> Rating.view ratingViewConfig model.ratingState
> , label []
> [ input
> [ type_ "checkbox"
> , checked model.readOnly
> , onClick ToggleReadOnly
> ]
> []
> , text "read only"
> ]
> ]


If however I write the following:

let
> defaultViewConfig = Rating.defaultViewConfig
> ratingViewConfig =
> { defaultViewConfig | readOnly = model.readOnly }
> in 

...


Then everything works fine. Is this a bug in the parser?

-- 
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.