Giter Club home page Giter Club logo

Comments (7)

robphoenix avatar robphoenix commented on September 24, 2024

Could we not just change :grade_2 to :grade_02?

iex(3)> Enum.sort([:grade_11, :grade_02])
[:grade_02, :grade_11]
iex(4)> Enum.sort([:grade_2, :grade_11]) 
[:grade_11, :grade_2]

Sorry I missed this.

from elixir.

rubysolo avatar rubysolo commented on September 24, 2024

Zero-padding inside a keyword feels like a hack, IMO.

I do like the explicitness of the :grade prefix -- what about using a tagged tuple for the grade?

iex(1)> Enum.sort([{:grade, 11}, {:grade, 2}])
[grade: 2, grade: 11]
iex(2)> Enum.sort([{{:grade, 11}, []}, {{:grade, 2}, []}])
[{{:grade, 2}, []}, {{:grade, 11}, []}]

It's a bit noisy, but (I think) a bit more Erlang-y.

from elixir.

robphoenix avatar robphoenix commented on September 24, 2024

Am I right in thinking this would mean the db is just an ordinary list, rather than a keyword list, and therefore the data in it is only accessible by index or by recursion/map/filter through the list until you get a pattern match on, say, grade? ie.

iex(29)> db |> Enum.filter(fn({{:grade, x}, y}) -> x == 2 end)
[{{:grade, 2}, ["Aimee"]}]  

How would you add multiple people to a grade? It seems to me that that would be a different operation to adding the first person to an empty grade, or to an empty db, unless you had the db structure already in place?

Could a list of maps be used perhaps?

db = [%{1 => ["Aimee"]}, %{2 => ["John", "Matt"]}]

I'm probably missing something, or overthinking this, but I'm having a hard time understanding how you would operate on this if it's not a keyword list or a map. I don't have any Erlang experience, but afaik using a keyword list or a map would be the Elixir-y way to approach the problem?

from elixir.

rubysolo avatar rubysolo commented on September 24, 2024

I think keyword list or map work well for the internal representation of the data, but maybe not as well for the value returned by sort, since it obviously needs to maintain sort order.

from elixir.

robphoenix avatar robphoenix commented on September 24, 2024

Thinking about this again today, I agree with @parkerl that reverting back to using a map but have the sort return a two-tuple list, is probably the best resolution to this. I see what you mean now @rubysolo about separating (& differentiating between) the internal representation of the data and what is returned by a function, such as sort.
I'm happy to make the changes (undo my mistake 😁 ) depending on what you both think.

from elixir.

rubysolo avatar rubysolo commented on September 24, 2024

👍

from elixir.

parkerl avatar parkerl commented on September 24, 2024

Closed by #118

from elixir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.