Skip to content

Commit

Permalink
Avoid piping into anonymous functions (#2117)
Browse files Browse the repository at this point in the history
* avoid piping into anonymous functions

* use kernel tail
  • Loading branch information
anthonyshull authored Jun 28, 2024
1 parent 717ec0e commit 81ee54b
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
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.tl()
|> 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.tl()
|> 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 @@ -73,7 +73,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

0 comments on commit 81ee54b

Please sign in to comment.