You're going on a trip with some students and it's up to you to keep track of how much money each Student has. A student is defined like this:
cla...
For further actions, you may consider blocking this person and/or reporting abuse
there is nothing more beautiful than Python
Usage:
Hi, check this decorator :
docs.python.org/3/library/functool...
Will make you avoid writing some functions.
Thank you Héctor i didn't know about this.
I've tried to apply it but it looks is a little shady for me, i didn't quite understand what is does and how it "magically" does the comparison
My first attempt at F#
I couldn't get the syntax highlighting for F# so if anyone can point me in the right direction that would be much appreciated.
renders as
(HEY, dev.to maintainers, this is one of those "won't fix bugs!" 😠 Why can't I nest backticks as in the github flavored markdown spec?)
Thank you
I put myself in here as a test case as a joke because I didn't get an allowance as a kid 😂
education.go
education_test.go
Javascript:
Usage:
Thank you Michael. I have been following your F# posts in this series and found them very helpful.
I thought about using a record type but thought it would be easier to use a class property for the match function.
If you get chance please could you show how you would approach the full solution.
Many thanks.
Ridiculously over-engineered Kotlin version:
It's typesafe, and we could change the comparator out if we wanted to. A little kludgey in the fold section (I should probably involve Option to avoid people accidentally calling money on the
Empty
andError
types. 🤷♀️While I love the
sealed class
idea in Kotlin, type erasure and lack of true pattern matching really hampers the readability. If I was able to rely onStudentAccumulator
auto-casting to its internal types, then I could remove a when statement that just dispatches out to the same overloaded call with the proper type.Ok, I fixed it. It's not too much uglier with proper Option protection...
My try with python
In Scala -
Here is the Python code snippets:
My Python attempt :
Using total_ordering decorator from func_tools, which only requires two implementations of the comparison methods.
Wow. Very good. I was nowhere near getting this. I need to spend some time working through your solution.
Thank you - it is very instructional. I really like how you show your tests as well. I haven't quite got my head around setting up tests in F# yet.