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

added Gleam version #17

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions expensereport-gleam/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
14 changes: 14 additions & 0 deletions expensereport-gleam/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Installing and Running

This kata was created for gleam 0.30.0.
You may have to run

```
gleam update
```

to get up to date `stdlib` if you run a newer version of the compiler. Then:

```
gleam run
```
2 changes: 2 additions & 0 deletions expensereport-gleam/gleam.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = "expense_report"
dependencies = { gleam_stdlib = "~> 0.30" , birl = "~> 0.14"}
12 changes: 12 additions & 0 deletions expensereport-gleam/manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This file was generated by Gleam
# You typically do not need to edit this file

packages = [
{ name = "birl", version = "0.14.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "ranger"], otp_app = "birl", source = "hex", outer_checksum = "4C9A60041E770D02FBD65A5B774026CD536B45A6AFDDBFC601A4450567AEE313" },
{ name = "gleam_stdlib", version = "0.30.2", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "8D8BF3790AA31176B1E1C0B517DD74C86DA8235CF3389EA02043EE4FD82AE3DC" },
{ name = "ranger", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "ranger", source = "hex", outer_checksum = "A3D54DD2BFCC654F1AA7A0D245F6F59A5D9FF6B2D68449C849BFE321E945EA7A" },
]

[requirements]
birl = { version = "~> 0.14" }
gleam_stdlib = { version = "~> 0.30" }
60 changes: 60 additions & 0 deletions expensereport-gleam/src/expense_report.gleam
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import gleam/int
import gleam/list.{fold}
import gleam/io.{println}
import birl/time

type ExpenseType {
Dinner
Breakfast
CarRental
}

type Expense {
Expense(expense_type: ExpenseType, amount: Int)
}

fn print_report(expenses: List(Expense)) {
println("Expense Report: " <> time.to_http(time.now()))
let [meal_expenses, total] =
fold(
expenses,
[0, 0],
fn(acc, expense) {
let [meal_expenses, total] = acc
let meal_expenses = case
expense.expense_type == Dinner || expense.expense_type == Breakfast
{
True -> meal_expenses + expense.amount
False -> meal_expenses
}
let expense_name = case expense.expense_type {
Dinner -> "Dinner"
Breakfast -> "Breakfast"
CarRental -> "Car Rental"
}
let meal_over_expenses_marker = case
expense.expense_type == Dinner && expense.amount > 5000 || expense.expense_type == Breakfast && expense.amount > 1000
{
True -> "X"
False -> " "
}
println(
expense_name <> "\t" <> int.to_string(expense.amount) <> "\t" <> meal_over_expenses_marker,
)
let total = total + expense.amount
[meal_expenses, total]
},
)
println("Meal Expenses: " <> int.to_string(meal_expenses))
println("Total Expenses: " <> int.to_string(total))
}

pub fn main() {
print_report([
Expense(Dinner, 5000),
Expense(Dinner, 5001),
Expense(Breakfast, 1000),
Expense(Breakfast, 1001),
Expense(CarRental, 4),
])
}