Re: [elm-discuss] `Case of` branches grouping

2016-12-09 Thread Petr Huřťák
I generally don't like using equality test on union types because that 
makes your code more prone to errors - later on you might decide to add / 
remove some types from union type.

On Friday, December 9, 2016 at 4:57:48 PM UTC+1, Nick H wrote:
>
> You can also do equality tests on type values, which means in your first 
> two cases you can use an if statement.
>
> if someValue == A then
>   stuff1
> else
>   stuff2
>
> This only works if your type values aren't storing any data.
>
> On Fri, Dec 9, 2016 at 7:25 AM, Petr Huřťák <petr@gmail.com 
> > wrote:
>
>> Hi,
>>
>> I would like hear some discussion on grouping of branches in `case of` 
>> statement . Currently it is not possible to use one branch for multiple 
>> conditions.
>>
>> Something along these lines:
>>
>> case someTypeValue of
>> A ->
>> -- code
>>
>> B ->
>> C ->
>> D ->
>> -- different code
>>
>>
>> Current alternative is this
>>
>> case someTypeValue of
>> let
>> stuff2 =
>> -- code  
>> in
>> A ->
>> -- different code
>>
>> B ->
>> stuff2
>>
>> C ->
>> stuff2
>> 
>> D ->
>> stuff2
>>
>>
>> Which is unnecessarily verbose and harder to read.
>>
>> One question is how this would work when there in cases where matched 
>> patterns have some values attached to them
>>
>> case someTypeValue of
>> A ->
>> -- stuff1
>>
>>
>> B _ ->
>> C _ _ ->
>> D _ _ _ ->
>> -- stuff2
>>
>> How is this handled in other languages like OCaml or Haskell?
>>
>> NOTE: moved from 
>> https://groups.google.com/forum/#!topic/elm-dev/DtUT2ieYTDo
>>
>> -- 
>> 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.


[elm-discuss] `Case of` branches grouping

2016-12-09 Thread Petr Huřťák
Hi,

I would like hear some discussion on grouping of branches in `case of` 
statement . Currently it is not possible to use one branch for multiple 
conditions.

Something along these lines:

case someTypeValue of
A ->
-- code

B ->
C ->
D ->
-- different code


Current alternative is this

case someTypeValue of
let
stuff2 =
-- code  
in
A ->
-- different code

B ->
stuff2

C ->
stuff2

D ->
stuff2


Which is unnecessarily verbose and harder to read.

One question is how this would work when there in cases where matched 
patterns have some values attached to them

case someTypeValue of
A ->
-- stuff1


B _ ->
C _ _ ->
D _ _ _ ->
-- stuff2

How is this handled in other languages like OCaml or Haskell?

NOTE: moved from https://groups.google.com/forum/#!topic/elm-dev/DtUT2ieYTDo

-- 
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] Task where I dont care if it fails

2016-09-07 Thread Petr Huřťák
I have been playing with the elm-lang/dom library, more specifically with 
the Dom.focus.
So far I have wired it up in my app the following way

focusElementCommand =
case invalidFieldId of
Just id ->
Task.perform (\_ -> Nope) (\_ -> Nope) 
(Dom.focus id)

Nothing ->
Cmd.none


So far I don't really care if the focus fails or succeds so I created Nope 
Msg which is just 

Nope ->
( model, Cmd.none )

The question is, is there any nicer way to do this without creating Nope 
Msg?

-- 
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] Decoding JSON with variable key names

2016-08-05 Thread Petr Huřťák
This works, thanks for help

On Friday, August 5, 2016 at 5:52:07 PM UTC+2, Janis Voigtländer wrote:
>
> Untested, but probably works:
>
> decoder = Json.Decode.dict Json.Decode.string |> Json.Decode.map (Dict.toList 
> >> List.map (\(name,value) -> Config name value))
>
> ​
>
> 2016-08-05 17:44 GMT+02:00 Petr Huřťák <petr@gmail.com >:
>
>> Hi,
>>
>> I have JSON from API with following data structure
>>
>> {
>>   "configurations": {
>> "configName1": "configValue1",
>> "configName2": "configValue2",
>> "configName2": "configValue3"
>>   }
>> }
>>
>>
>>
>> How do I construct Decoder which outputs data structure which is little 
>> easier to work with in elm, like following:
>>
>> type alias Configs = List Config
>>
>> type alias Config = 
>> { name : String
>> , value : String
>> }
>>
>>
>>
>> which would result with following Elm data structure
>>
>> configs : Configs
>> configs = 
>> [ { name: "configName1", value: "configValue1" } 
>> , { name: "configName2", value: "configValue2" } 
>> , { name: "configName3", value: "configValue3" } 
>> ]
>>
>> -- 
>> 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.


[elm-discuss] Decoding JSON with variable key names

2016-08-05 Thread Petr Huřťák
Hi,

I have JSON from API with following data structure

{
  "configurations": {
"configName1": "configValue1",
"configName2": "configValue2",
"configName2": "configValue3"
  }
}



How do I construct Decoder which outputs data structure which is little 
easier to work with in elm, like following:

type alias Configs = List Config

type alias Config = 
{ name : String
, value : String
}



which would result with following Elm data structure

configs : Configs
configs = 
[ { name: "configName1", value: "configValue1" } 
, { name: "configName2", value: "configValue2" } 
, { name: "configName3", value: "configValue3" } 
]

-- 
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] How to decode JSON object with more than 8 fields?

2016-08-01 Thread Petr Huřťák
For 8 fields or less I can do

import Json.Decode as Decode exposing ((:=))

collectionDecoder : Decode.Decoder (List Test)
collectionDecoder =
Decode.list
(Decode.object8 Test
("id" := Decode.int)
...
)


How to decode JSON object with more than 8 fields?

-- 
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] Outgoing port without parameters

2016-06-08 Thread Petr Huřťák
Hi,

I am trying to create outgoing (Elm -> JS) port, so far everything works as 
expected with this code:

port portName : String -> Cmd msg


But when I try to create port without parameters

port portName : Cmd msg


it doesen't provide helpful message

Port `portName` has an invalid type.


> 4| port portName : Cmd msg

   ^

You are saying it should be:


> Platform.Cmd.Cmd msg


> But you need to use the particular format described here:




> Detected errors in 1 module. 

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