Skip to content
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

Merged
merged 2 commits into from
Jun 3, 2024

Conversation

joshlarson
Copy link
Contributor

@joshlarson joshlarson commented May 30, 2024

@joshlarson joshlarson marked this pull request as ready for review May 30, 2024 23:14
@joshlarson joshlarson requested a review from a team as a code owner May 30, 2024 23:14
@joshlarson joshlarson enabled auto-merge (squash) May 30, 2024 23:24
@joshlarson joshlarson force-pushed the jdl/feat/backend-for-unfinished-route-segments branch from 49558bd to b32389e Compare May 31, 2024 21:30
Copy link

Coverage of commit b32389e

Summary coverage rate:
  lines......: 93.6% (3257 of 3480 lines)
  functions..: 73.4% (1343 of 1830 functions)
  branches...: no data found

Files changed coverage rate:
                                                                  |Lines       |Functions  |Branches    
  Filename                                                        |Rate     Num|Rate    Num|Rate     Num
  ======================================================================================================
  lib/skate/detours/route_segments.ex                             | 100%      9| 100%     4|    -      0
  lib/skate_web/controllers/detours_controller.ex                 | 100%     32|92.3%    13|    -      0
  lib/skate_web/router.ex                                         |88.9%     63|16.2%   136|    -      0

Download coverage report

Copy link
Collaborator

@hannahpurcell hannahpurcell left a 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

@joshlarson joshlarson merged commit 973e839 into main Jun 3, 2024
9 checks passed
@joshlarson joshlarson deleted the jdl/feat/backend-for-unfinished-route-segments branch June 3, 2024 13:30
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]}
Copy link
Member

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?

Copy link
Contributor Author

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}

Copy link
Member

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)

Comment on lines +42 to +47

{:ok,
%__MODULE__.UnfinishedResult{
before_start_point: Enum.slice(shape, 0..index) ++ [nearest_point],
after_start_point: [nearest_point] ++ Enum.slice(shape, (index + 1)..-1)
}}
Copy link
Member

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?

Suggested change
{: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
}}

Copy link
Contributor Author

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

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants