[elm-discuss] Re: Sort a list of strings independant of case

2016-09-11 Thread Sergey Zubtsovskiy
I see. I am not questioning usage of sortBy, my point was to provide an
alternative solution to what the post's author suggested because I thought
that direct implementation with List.map and then sort may be not suitable
in some cases.

Great that there is a better way but @Rudolf was asking for an example of
using sortWith as well.

суббота, 10 сентября 2016 г. пользователь Joey Eremondi написал:

> @Sergey Right, but the List.sortBy examples just sort based on the
> toUppercased version, but don't put the toUppercase results in the final
> list.
>
> sortBy is different than using List.map
>
> On Sat, Sep 10, 2016 at 1:00 PM, Sergey Zubtsovskiy <
> sergey.zubtsovs...@gmail.com> wrote:
>
>> Well, I meant that elements from original list will stay intact. If you
>> are first applying List.map toUppercase and then sort, resulting list will
>> contain uppercased letters which may be undesirable.
>>
>> In my solution resulting list will contain same elements as the original
>> one sorted in case-insensitive manner.
>>
>> I see this difference as significant and necessary.
>>
>> суббота, 10 сентября 2016 г. пользователь Max Goldstein написал:
>>
>>> not changing original list
>>>
>>>
>>> An an immutable language such as Elm, nothing can change the original
>>> list! I think you've more-or-less implemented List.sortBy explicitly, which
>>> is instructive, but not really necessary.
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Elm Discuss" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/elm-discuss/IwSIlRUoNFw/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> elm-discuss+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> --
>> Sergey Zubtsovskiy
>> sergey.zubtsovs...@gmail.com
>> Skype: szubtsovskiy
>>
>>
>> --
>> 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.
>>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/to
> pic/elm-discuss/IwSIlRUoNFw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Sergey Zubtsovskiy
sergey.zubtsovs...@gmail.com
Skype: szubtsovskiy

-- 
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: Sort a list of strings independant of case

2016-09-10 Thread Sergey Zubtsovskiy
Well, I meant that elements from original list will stay intact. If you are
first applying List.map toUppercase and then sort, resulting list will
contain uppercased letters which may be undesirable.

In my solution resulting list will contain same elements as the original
one sorted in case-insensitive manner.

I see this difference as significant and necessary.

суббота, 10 сентября 2016 г. пользователь Max Goldstein написал:

> not changing original list
>
>
> An an immutable language such as Elm, nothing can change the original
> list! I think you've more-or-less implemented List.sortBy explicitly, which
> is instructive, but not really necessary.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/elm-discuss/IwSIlRUoNFw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> elm-discuss+unsubscr...@googlegroups.com
> <javascript:_e(%7B%7D,'cvml','elm-discuss%2bunsubscr...@googlegroups.com');>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Sergey Zubtsovskiy
sergey.zubtsovs...@gmail.com
Skype: szubtsovskiy

-- 
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: Sort a list of strings independant of case

2016-09-10 Thread Sergey Zubtsovskiy

This is a solution not changing original list:

import Html exposing (text)
import String exposing (toUpper)

main =
  text (toString sortedList)
  
sortedList : List String
sortedList =
  [ "c", "B" , "a" ] |> List.sortWith compareIgnoreCase
  
compareIgnoreCase : String -> String -> Order
compareIgnoreCase a b =
  case compare (toUpper a) (toUpper b) of
LT -> LT
EQ -> EQ
GT -> GT

Efficiency can be improved by keeping a cache of already upper cased 
letters.


On Friday, September 9, 2016 at 5:45:01 PM UTC+2, Rudolf Bargholz wrote:
>
> Hi,
>
> Failing here dismally, so I hope someone here is kind enough to help out.
>
> *Problem*: I have a list of strings and want to sort the list independant 
> of the case of the chars in the string
>
> What I have so far:
>
> > import List
> > import String
> > unorderedList = [ "c", "B" , "a"]
> ["c","B","a"] : List String
> > orderedList = List.sort unorderedList
> ["B","a","c"] : List String
> > orderedList2 = unorderedList |> List.map String.toUpper |> List.sort
> ["A","B","C"] : List String
>
>
> What I am trying to acheive is the following result:
>
> ["a","B","c"] : List String
>
> I must be overlooking something easy. 
>
> Could anyone point me in the right direction how I can accomplish this?
> Is there any resource that has numerous Elm examples on how to use 
> *List.sort*, *List.sortBy* and *List.sortWith*?
>
> Regards
>
> Rudolf Bargholz
>

-- 
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: Debugging json decoders

2016-08-20 Thread Sergey Zubtsovskiy
Thank you for explanation! I should give it a try.

Sergey Zubtsovskiy
sergey.zubtsovs...@gmail.com
Skype: szubtsovskiy


2016-08-19 23:06 GMT+02:00 OvermindDL1 <overmind...@gmail.com>:

> Given this:
> ```elm
> onScroll tagger =
>   on "scroll" (Json.Decode.map tagger decodeScrollPosition)
> ```
> If you *always* want it to be called, and since we know in this case that
> the scroll javascript event will not return a negative number then you
> could do this for decodeScrollPosition:
> ```elm
> decodeScrollPosition =
>   Json.Decode.oneOf
> [ Json.Decoder.int
> , Json.Decoder.succeed -1
> ]
> ```
>
> Or you could parse out a `Maybe Int`, or you could parse out a structure
> if you want a more stuff.  Etc...  :-)
>
>
> On Friday, August 19, 2016 at 2:45:32 PM UTC-6, Sergey Zubtsovskiy wrote:
>>
>> I am not sure I understand the answer. If you are talking about calling
>> decode function then, as Jacob mentioned, it works in all cases but the one
>> we're wondering about.
>>
>> Check this example:
>>
>> onScroll tagger =
>>>   on "scroll" (Json.Decode.map tagger decodeScrollPosition)
>>
>>
>> Where decodeScrollPosition is:
>>
>>> decodeScrollPosition : Json.Decode.Decoder Int
>>
>>
>> "on" function is only accepting value of type Json.Decode.Decoder. If I
>> was decoding myself (e.g. by calling Json.Decode.decodeString) I would get
>> a Result and process it the way you mention. But in case of an event
>> listener decoding is happening somewhere within Elm runtime which silently
>> swallows error. If I, for example, misspell event's field name, nothing
>> will happen. No runtime error (that's still valid), but no result either.
>>
>> I am wondering if I am missing something. To my mind it does not fit to
>> the whole impression Elm's trying to create. And I am a bit confused.
>>
>> Sergey Zubtsovskiy
>> sergey.zu...@gmail.com
>> Skype: szubtsovskiy
>>
>>
>> 2016-08-19 21:31 GMT+02:00 Simon <hotb...@gmail.com>:
>>
>>> 
>>> My emulator may help - http://simonh1000.github.io/decoder/
>>> 
>>>
>>> On Friday, 19 August 2016 19:56:05 UTC+2, OvermindDL1 wrote:
>>>
>>> On Friday, August 19, 2016 at 11:17:45 AM UTC-6, Sergey Zubtsovskiy
>>>> wrote:
>>>>>
>>>>> Hey Jacob,
>>>>>
>>>>> Any update on this topic? I am facing the same issue, even in Elm 0.17
>>>>> with latest libraries...
>>>>>
>>>>
>>>> You can setup multiple branches in a decode so it one fails then you
>>>> can fall back to a default value so it still passes.  You could even return
>>>> a Maybe and return a default value of Nothing if you want, wrapping the
>>>> main decode branch in a Just.
>>>>
>>> ​
>>>
>>> --
>>> 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.
>

-- 
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: Debugging json decoders

2016-08-19 Thread Sergey Zubtsovskiy
I am not sure I understand the answer. If you are talking about calling
decode function then, as Jacob mentioned, it works in all cases but the one
we're wondering about.

Check this example:

onScroll tagger =
>   on "scroll" (Json.Decode.map tagger decodeScrollPosition)


Where decodeScrollPosition is:

> decodeScrollPosition : Json.Decode.Decoder Int


"on" function is only accepting value of type Json.Decode.Decoder. If I was
decoding myself (e.g. by calling Json.Decode.decodeString) I would get a
Result and process it the way you mention. But in case of an event listener
decoding is happening somewhere within Elm runtime which silently swallows
error. If I, for example, misspell event's field name, nothing will happen.
No runtime error (that's still valid), but no result either.

I am wondering if I am missing something. To my mind it does not fit to the
whole impression Elm's trying to create. And I am a bit confused.

Sergey Zubtsovskiy
sergey.zubtsovs...@gmail.com
Skype: szubtsovskiy


2016-08-19 21:31 GMT+02:00 Simon <hotbe...@gmail.com>:

> 
> My emulator may help - http://simonh1000.github.io/decoder/
> 
>
> On Friday, 19 August 2016 19:56:05 UTC+2, OvermindDL1 wrote:
>
> On Friday, August 19, 2016 at 11:17:45 AM UTC-6, Sergey Zubtsovskiy wrote:
>>>
>>> Hey Jacob,
>>>
>>> Any update on this topic? I am facing the same issue, even in Elm 0.17
>>> with latest libraries...
>>>
>>
>> You can setup multiple branches in a decode so it one fails then you can
>> fall back to a default value so it still passes.  You could even return a
>> Maybe and return a default value of Nothing if you want, wrapping the main
>> decode branch in a Just.
>>
> ​
>
> --
> 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.
>

-- 
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: Debugging json decoders

2016-08-19 Thread Sergey Zubtsovskiy
Hey Jacob,

Any update on this topic? I am facing the same issue, even in Elm 0.17 with 
latest libraries...

On Tuesday, November 3, 2015 at 11:16:53 PM UTC+1, Jacob Matthews wrote:
>
>
> I've been playing with Elm recently. I really like it in general, but I 
> have had some pretty frustrating experiences debugging Json.Decode.Decoder 
> failures, especially while handling browser events using Html.Events.on.
>
> For instance, suppose we want to write a decoder that reads the selected 
> index within a  element. We might write:
>
> import Json.Decode exposing (..)
>
> ...
>
> decodeSelectedIndex : Decoder string
> decodeSelectedIndex = at ["action", "selectedIndex"] string  -- oops! 
> selectedIndex is an int!
>
> renderSelect : Html
> renderSelect = 
>   select 
> [ on "change" decodeSelectedIndex someHandler ]
> [ ... ]
>   
> The problem here is that the decoder doesn't match the value being parsed, 
> but we can't figure out any way to either observe the raw value 
> pre-decoding (using Debug.watch, Debug.log or even a javascript 
> breakpoint) or to convince Html.Events.on to report an error if parsing 
> fails -- the handler just doesn't fires, with no indication of why.
>
> I tried creating a monitoring function 
>
> monitorDecoder : Decoder a -> Decoder a
> monitorDecoder decoder = 
>   customDecoder Json.Decode.value <| \value -> decodeValue decoder 
> (Debug.watch "decoding value" value)
>
> so that I could write 
>
>on "change" (monitorDecoder decodeSelectedIndex) someHandler
>
> but that approach always fails to decode before the watch gets evaluated 
> -- I'm not sure why, but I suspect it's because the decoder is being asked 
> to decode a JavaScript event, which is not JSON-serializable, and thus the 
> Json.Decode.value decoder fails before the custom decoding logic runs at 
> all.
>
> Are there other strategies I can try? What do people normally do to write 
> solid decoders? I really like Elm in general but I'm worried about not 
> having an effective way to debug these kinds of issues.
>
> Thanks,
> -jacob
>

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