-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add backend for route segments for unfinished detours #2637
feat: Add backend for route segments for unfinished detours #2637
Conversation
49558bd
to
b32389e
Compare
Coverage of commit
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I'm delighted, this was a perfect bite-size of detour logic that helped things come into focus a bit better. ✅ Readable ✅ Logical
after_start_point: [Util.Location.From.t()] | ||
} | ||
@enforce_keys [:before_start_point, :after_start_point] | ||
@derive {Jason.Encoder, only: [:before_start_point, :after_start_point]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question(non-blocking): why specify only
here if it includes all keys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied it from the other route segments result, but it looks like that also maybe doesn't need only
?
I'm kind of new to the world of Jason
, so would it be better to just omit the only:
section entirely, and have it say 👇?
@enforce_keys [:before_start_point, :after_start_point]
@derive {Jason.Encoder}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given I wrote the first one with @enforce_keys
, I'm not really sure why I did that in retrospect, I think just because I'd never used @derive
before I was curious and it "seemed" right. I don't think I agree with my decision anymore, but it's not a big deal that it's like this.
(also, dang, I really wanted replying via email to work)
|
||
{:ok, | ||
%__MODULE__.UnfinishedResult{ | ||
before_start_point: Enum.slice(shape, 0..index) ++ [nearest_point], | ||
after_start_point: [nearest_point] ++ Enum.slice(shape, (index + 1)..-1) | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question(non-blocking): I find the overhead of understanding this slightly annoying, could we use Enum.split
instead?
Something like this?
{:ok, | |
%__MODULE__.UnfinishedResult{ | |
before_start_point: Enum.slice(shape, 0..index) ++ [nearest_point], | |
after_start_point: [nearest_point] ++ Enum.slice(shape, (index + 1)..-1) | |
}} | |
[shape_before_start_point, shape_after_start_point] = Enum.split(shape, index) | |
{:ok, | |
%__MODULE__.UnfinishedResult{ | |
before_start_point: shape_before_start_point ++ [nearest_point], | |
after_start_point: [nearest_point] ++ shape_after_start_point | |
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh huh - I assumed that Enum.split/2
would work more similarly to String.split/3
, so it didn't even occur to me to do it this way.
But unless I'm missing something, your way is a lot cleaner, both for this and for the other route segments function - will do a follow-up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://hexdocs.pm/elixir/1.17.0-rc.1/enum-cheat.html has been very helpful for me fwiw.
Asana Ticket: https://app.asana.com/0/1205385723132845/1207449517841757/f