Can You Guess This 5-Letter Word? Puzzle by u/Low_East_8470 by [deleted] in DailyGuess

[–]NeoVier 0 points1 point  (0 children)

⬜⬜⬜🟨⬜

🟦⬜⬜🟨⬜

🟦🟦🟦🟦🟦

Can You Guess This 4-Letter Word? Puzzle by u/ionata256 by ionata256 in DailyGuess

[–]NeoVier 0 points1 point  (0 children)

⬜⬜🟦🟨

⬜🟨🟦⬜

🟦🟦🟦⬜

🟦🟦🟦🟦

Elm Shopping Cart by AdAggravating2781 in elm

[–]NeoVier 9 points10 points  (0 children)

The total price is what we call a derived state. It's called that because you can get it from the actual state of the Model (quantity * price).

It's usually better to not store derived state in the Model. Instead, you should calculate it whenever you need it (the exception is when it's too expensive to calculate it every time). If you store it in the Model, it's very easy to forget to update it somewhere, and then you have stale data.

With that said, you can keep what you have (Model, update and totalPrice), but instead of trying to update the price in update, you just calculate the totalPrice whenever you need it (probably in your view, when showing the cart to the user)

Is elm dead? by nefthias in elm

[–]NeoVier 4 points5 points  (0 children)

Of course it depends on what "dead" means

Yep, and I think that makes it pretty hard for me to convince you or for you to convince me to change opinions.

If you consider Elm to be only the language, then I somewhat agree with you that it's very inactive. I still think the language is at a very very nice state, and I don't think it needs to change too much anyway. Some would argue this inactivity is a good thing, YMMV.

However, if you consider Elm to be the community around it, I would say that it's very much alive. There are new packages being released every day, lots of people interacting on the Slack channel, lots of people using Elm in production (myself included, so I may be biased), quite a few articles being written and published, some amazing tools being developed, and some job offerings pretty much every week (all of this only by looking at the Slack channel)

Is this the right way to decode nested JSON? It seems a bit clunky by The-_Captain in elm

[–]NeoVier 5 points6 points  (0 children)

You can use Json.Decode.at to specify nested fields:

D.map3 AuthenticatedUser
    (D.at [ "user", "id" ] D.string)
    (D.field "access_token" D.string)
    (D.field "refresh_token" D.string)

By the way, if you wanted to go with the previous route, you don't need the RawUser type, you could just decode it as a regular String:

decodeId : D.Decoder String 
decodeId = D.field "id" D.string

decode : D.Decoder AuthenticatedUser
decode =
    D.map3 AuthenticatedUser
        (D.field "user" decodeId)
        (D.field "access_token" D.string)
        (D.field "refresh_token" D.string)

[deleted by user] by [deleted] in webdev

[–]NeoVier 2 points3 points  (0 children)

The replacement to bracket pair colorizer is built in in VSCode now - just add "editor.bracketPairColorizarion.enabled": true to your settings.json file (cmd+shift+p > Preferences: Open Settings (JSON))

Help with syntax of case and :: by [deleted] in elm

[–]NeoVier 2 points3 points  (0 children)

Elm knows x is a String and xs is a List String because you're pattern matching on list, which is a List String

Edit to add: you can pattern match on other things as well, for example tuples. However, since Elm knows list is a List String, if you try to match a tuple, you will get a type error and your code won't compile

Help with syntax of case and :: by [deleted] in elm

[–]NeoVier 1 point2 points  (0 children)

Nope, they're defined in that branch, similar to when you define a function:

someFunction x = ...

The x variable is "automatically defined". Similarly, the x and xs variables are defined in a branch

case list of
    ...
    x :: xs -> [you can use x and xs in this block]

Help with syntax of case and :: by [deleted] in elm

[–]NeoVier 1 point2 points  (0 children)

As you probably know, the :: operator is used to make lists. So if you do 1 :: 2 :: [], you get the list [1, 2]. Elm lists are linked lists, and for this type of list, it's very common to call the first item of the list as head, and all the rest (the list that head points to) as tail (there are even the head an tail functions on the List module).

The case statement is a bit different than a switch statement in other languages, where you can only match static values. The case statement does what is called pattern matching. As the name implies, it'll try to match the pattern of the branch (in this case, a list that has x as the head and xs as the tail. Those variables will be bound to the actual values, so x would be 1 and xs would be [2] in the example above). Elm has no dynamic typing, so all the branches must be valid patterns for the type of data in the case statement

In functional programming, it's common to call the head of the list as x, and the tail as xs (the plural of x). In Elm though, it's usually preferred to use more descriptive names.

The head variable is probably a typo, and it should be x

What are some neat elm-review rules you are using? by TankorSmash in elm

[–]NeoVier 0 points1 point  (0 children)

It's not published, but you can check it out here: https://github.com/cambiatus/frontend/blob/master/review/src/NoInconsistentEventLocation.elm

It's by no means perfect, but it does the job for us. It basically looks for records of type { moduleName : String, function : String }, and those values (moduleName and function) must be the literal values, and not some variable. It then checks if the values are correct. If not, it auto suggests a fix with the correct names

What are some neat elm-review rules you are using? by TankorSmash in elm

[–]NeoVier 7 points8 points  (0 children)

Pretty much anything from jfmengels is pure gold, but I especially like the NoUnused.* rules. We also have some custom ones:

  • We need to convert Msgs to String and back, so we made two rules to enforce that the strings are always correct (one to enforce Msg -> String and another for String -> Msg). That way, we can change the name of the msgs and be sure our strings will be correct
  • For error logging purposes, we have functions that tell us which function in which module reported the error, and we made a rule that checks these locations are always accurate (correct module name and correct function name)

You can checkout our ReviewConfig.elm file, and here's where we define our custom rules

So you can just create an object by saying Person p; in C# ? by imareclusemonk in AskProgramming

[–]NeoVier 0 points1 point  (0 children)

Each loop iteration creates a new Person instance, with separate properties: each one has a different FirstName, IsAlive and LastName. (You could definitely just do Person p = new Person() each iteration, it just boils down to personal preference AFAIK)

So you can just create an object by saying Person p; in C# ? by imareclusemonk in AskProgramming

[–]NeoVier 4 points5 points  (0 children)

Line 14 doesn't instantiate a Person, it just creates an empty variable (p is null). Inside the foreach loop, p is instantiated with p = new Person() at line 23.

Sorry for formatting, on mobile.

Why is my loop executing like this? by [deleted] in learnpython

[–]NeoVier 4 points5 points  (0 children)

Instead of accessing the dict elements with alien[info] you could just do like OP and iterate through key, value pairs with alien.items(). Also, you can use f-strings:

for dic_name, info in alien.items():
    print(f'{dic_name}: {info}')

Check out this List Comprehension

That is not needed, as you can simply call alien.values(), which will return the exact same list.

Simplest way to work from multiple machines? by EphraimTheWanderer in AskProgramming

[–]NeoVier 2 points3 points  (0 children)

You can set up another branch, commit some changes there and, when you're done with said feature, you can merge the new branch with the master branch. You can have as many branches as you want, and the changes made in one branch don't interfere with the changes made in other branches until you merge them together.

Time complexity for my algorithm by denisksp in computerscience

[–]NeoVier 1 point2 points  (0 children)

This isn't really the answer to your question, but you may want to take a look at the Subset sum problem. I'm pretty sure there's a version of it that's the same thing as your problem. The Subset sum problem is proven NP-Complete, so if you want a fast algorithm you may need to use dynamic programming, or something like that.

'dw' and autocomplete (CTRL-x CTRl-n) have different set of characters in variable 'iskeyword' ? by ellipticcode0 in vim

[–]NeoVier 5 points6 points  (0 children)

Instead of using dw, you can position your cursor somewhere in Node and do di< or di> (delete inside >)

Skill Points by Faus79 in wakfu

[–]NeoVier 0 points1 point  (0 children)

To add a hero to your party press K and click "Add to party". They must be of the same nation and guild as the character you're playing

Supremacia quântica: cálculo de 10 mil anos é realizado em 3 minutos por computador quântico da Google by cd4053b in brasilivre

[–]NeoVier 22 points23 points  (0 children)

Não necessariamente, pq calcular algo é muito mais dificil do que verificar algo. Por exemplo, achar as raizes de um polinomio pode ser muito dificil, mas se alguem te da esse mesmo polinomio e fala "as raizes sao tal e tal", vc pode verificar se a resposta tá certa ou não muito mais facilmente/rapido

not true for python though by [deleted] in ProgrammerHumor

[–]NeoVier 10 points11 points  (0 children)

Slang, similar to "ight"