Skip to content

Commit

Permalink
♻️ Use Amount transformers instead of 1m<dd>
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyfran committed Jan 16, 2024
1 parent 672a30b commit 64954ee
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module SetupMerchStandCommand =
let price =
$"How much do you want to charge for {Generic.itemDetailedName item |> Styles.item}? (Recommended: {Styles.money recommendedPrice})"
|> showDecimalPrompt
|> (*) 1m<dd>
|> Amount.fromDecimal

let result = setPrice band item price

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let distributeFunds bankApp =

let result =
showDecimalPrompt "How much would you like to distribute?"
|> (*) 1m<dd>
|> Amount.fromDecimal
|> FundDistribution.distribute state

match result with
Expand Down
7 changes: 4 additions & 3 deletions src/Duets.Cli/Text/Phone.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ let concertAssistantAppShowCityPrompt = "In which city?"

let concertAssistantAppShowVenuePrompt = "In which venue?"

let concertAssistantAppTicketPricePrompt =
$"""What will the price of each ticket be? {Styles.danger
"Keep in mind that putting high prices might affect how many people will go"}"""
let concertAssistantAppTicketPricePrompt recommendedPrice =
$"""What will the price of each ticket be? (Recommended: {recommendedPrice |> Styles.money})
{Styles.danger
"Keep in mind that putting high prices might affect how many people will go"}"""

let concertAssistantAppDateAlreadyBooked date =
Styles.error $"You already have a concert on {Date.simple date}!"
Expand Down
6 changes: 6 additions & 0 deletions src/Duets.Entities/Amount.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ module Duets.Entities.Amount

/// Creates an amount from a decimal value.
let fromDecimal (amount: decimal) : Amount = amount * 1m<dd>

/// Creates an amount from a float value.
let fromFloat (amount: float) : Amount = amount |> decimal |> fromDecimal

/// Concerts an amount to a decimal value.
let toDecimal (amount: Amount) : decimal = amount / 1m<dd>
2 changes: 1 addition & 1 deletion src/Duets.Simulation/Albums/Revenue.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ let albumRevenue (previousDayStreams: int) =
float previousDayStreams
* Config.Revenue.revenuePerStream
|> decimal
|> (*) 1m<dd>
|> Amount.fromDecimal
2 changes: 1 addition & 1 deletion src/Duets.Simulation/Concerts/DailyUpdate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open Duets.Entities
open Duets.Simulation

let private ticketPriceModifier state bandId concert =
let ticketPrice = concert.TicketPrice / 1m<dd> |> float
let ticketPrice = concert.TicketPrice |> Amount.toDecimal |> float

let ticketPriceCap = Queries.Concerts.fairTicketPrice state bandId |> float

Expand Down
2 changes: 1 addition & 1 deletion src/Duets.Simulation/Flights/TicketGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ let private createTicket origin destination date dayMoment =
Queries.World.distanceBetween origin destination
|> decimal
|> (*) Config.Travel.pricePerKm
|> (*) 1m<dd>
|> Amount.fromDecimal

Flight.create origin destination ticketPrice date dayMoment
3 changes: 1 addition & 2 deletions src/Duets.Simulation/Queries/Albums.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ module Albums =
/// Calculates the generated revenue of the album.
let revenue album =
float album.Streams * Config.Revenue.revenuePerStream
|> decimal
|> (*) 1m<dd>
|> Amount.fromFloat

0 comments on commit 64954ee

Please sign in to comment.