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

Avoid piping into anonymous functions #2117

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/dotcom/cache/key_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Dotcom.Cache.KeyGenerator do
mod
|> Kernel.to_string()
|> String.split(".")
|> (fn [_ | tail] -> tail end).()
|> Kernel.then(fn [_ | tail] -> tail end)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like using then doesn't actually help what this credo check is for. The goal of the check is to improve readability and this doesn't make it better, just changes it. I think moving these to named functions would improve readability. This example replacing it with Kernel.tl would solve this problem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense, I was looking for a function named tail and couldn't find one.

|> Enum.map_join(".", &Recase.to_snake/1)
|> String.downcase()
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dotcom/cache/trip_plan_feedback/key_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Dotcom.Cache.TripPlanFeedback.KeyGenerator do
mod
|> Kernel.to_string()
|> String.split(".")
|> (fn [_ | tail] -> tail end).()
|> Kernel.then(fn [_ | tail] -> tail end)
|> Enum.map_join(".", &Recase.to_snake/1)
|> String.downcase()
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dotcom/trip_plan/map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ defmodule Dotcom.TripPlan.Map do

polyline
|> Polyline.decode()
|> (fn line -> Enum.concat([[from], line, [to]]) end).()
|> Kernel.then(fn line -> Enum.concat([[from], line, [to]]) end)
|> Polyline.encode()
end

Expand Down
2 changes: 1 addition & 1 deletion lib/dotcom_web/controllers/schedule/schedule_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule DotcomWeb.ScheduleController.ScheduleApi do
fn trip_id ->
services_by_trip[trip_id]
|> List.first()
|> (fn sched -> sched.time end).()
|> Map.get(:time)
end,
&date_sorter/2
)
Expand Down
2 changes: 1 addition & 1 deletion lib/trip_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ defmodule TripInfo do
List
|> apply(list_function, [times])
|> PredictedSchedule.stop()
|> (fn stop -> stop.id end).()
|> Map.get(:id)
end

defp do_from_list(
Expand Down
10 changes: 5 additions & 5 deletions test/dotcom_web/controllers/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ defmodule DotcomWeb.ControllerHelpersTest do
|> assign(:route, route)
|> assign(:direction_id, 1)
|> assign_alerts([])
|> (fn conn -> conn.assigns.alerts end).()
|> Kernel.then(fn conn -> conn.assigns.alerts end)

expected = [@commuter_rail_alert, @worcester_alert, @worcester_inbound_alert]
assert alerts == expected
Expand All @@ -231,7 +231,7 @@ defmodule DotcomWeb.ControllerHelpersTest do
|> assign(:route, route)
|> assign(:direction_id, 0)
|> assign_alerts([])
|> (fn conn -> conn.assigns.alerts end).()
|> Kernel.then(fn conn -> conn.assigns.alerts end)

expected = [@commuter_rail_alert, @worcester_alert]
assert alerts == expected
Expand All @@ -246,7 +246,7 @@ defmodule DotcomWeb.ControllerHelpersTest do
|> assign(:route, route)
|> assign(:direction_id, nil)
|> assign_alerts([])
|> (fn conn -> conn.assigns.alerts end).()
|> Kernel.then(fn conn -> conn.assigns.alerts end)

expected = [@commuter_rail_alert, @worcester_alert, @worcester_inbound_alert]
assert alerts == expected
Expand All @@ -260,7 +260,7 @@ defmodule DotcomWeb.ControllerHelpersTest do
|> assign(:date_time, Timex.now())
|> assign(:route, route)
|> assign_alerts([])
|> (fn conn -> conn.assigns.alerts end).()
|> Kernel.then(fn conn -> conn.assigns.alerts end)

expected = [@commuter_rail_alert, @worcester_alert, @worcester_inbound_alert]
assert alerts == expected
Expand Down Expand Up @@ -294,7 +294,7 @@ defmodule DotcomWeb.ControllerHelpersTest do
|> assign(:route, route)
|> assign(:direction_id, 0)
|> assign_alerts([])
|> (fn conn -> conn.assigns.alerts end).()
|> Kernel.then(fn conn -> conn.assigns.alerts end)

expected = [@commuter_rail_alert, @worcester_alert, worcester_ambiguous_alert]
assert alerts == expected
Expand Down
Loading