Comments (7)
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.
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.
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.
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.
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.
👍
from elixir.
Closed by #118
from elixir.
Related Issues (20)
- Adjust all concepts to use charlist sigils
- test_exercises.sh print fails when test output includes `%`
- Lasagna exercise HOT 2
- Why does this repository have two identical github workflows? HOT 6
- Phone Number exercise: difference between tests in exercise folder vs online Test runner HOT 2
- Implement new practice exercise: bottle-song
- Too forgiving test in exercises/concept/german-sysadmin HOT 1
- Mistakes in `bottle-song` example solution typespecs HOT 3
- [RPG Character Sheet] Misleading the 5th question HOT 4
- Building a training set of tags for elixir HOT 22
- Run on Elixir 1.16
- Leap approaches for 48in24
- 48in24 Approaches for Raindrops HOT 2
- Darts exercise hint for sqrt workaround doesn't seem to work HOT 7
- Typo In Take-A-Number Deluxe Step 6 HOT 2
- Take-A-Number not enough information HOT 5
- Rational Numbers "abs"/1 function is colliding with Kernel.abs/1 HOT 1
- Pig Latin. Tests and Description seems to diverge HOT 1
- Lucas Numbers HOT 1
- Newsletter task instruction confusing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elixir.