fchabouis

fchabouis

I am wondering why there is no min and max functions in Elixir for DateTime. Currently, you need to write something like :

if DateTime.compare(d1, d2) == :lt, do: d1, else: d2

Is there any reason why there is no DateTime.min(d1,d2) ?

Showing Posts 1 to 5

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Fun fact, you can do this with Enum!

Enum.min([d1, d2], DateTime)
18
Post #1
pdgonzalez872

pdgonzalez872

Very cool! Thanks for sharing @benwilson512 ! I’m looking at the docs for Date and I’m not sure about:

  • where to include this tidbit (super useful, even more for new folks coming into the language)
  • if we should include it in docs at all?

This is where I was looking by the way: elixir/lib/elixir/lib/calendar/date.ex at main · elixir-lang/elixir · GitHub

This was a TIL for me, usually date comparison was handled by a library in a few of the projects I’ve worked on in the past. This is great to know.

fchabouis

fchabouis OP

Very interesting !

The introduction of the DateTime module says

image

It could be a good place to add information about the fact that the existence of the compare\2 function allows to use Enum.min\2

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Agreed, I think that’d be exactly the right spot.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

wmnnd
Hey folks, I wanted to share with you a project I’ve been working on for a while: It’s an Open Source (AGPLv3) newsletter tool. Think Ma...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
sntran
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
Ganna
Hi everyone, I have 8 years of production experience with Erlang/OTP and I’m just starting to get to know Elixir. What would you learn f...
New
johnkirkham
A note on form. Joe Armstrong, co-creator of the Erlang programming language, died in April 2019. What follows is a work of narrative non...
New
gtcode
I’ve been tinkering with Lynx (by José) via hold_ledger. I used AI to write the code, a separate specification, the tests, and the Lean p...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews