Last active
November 1, 2016 22:23
-
-
Save sergiors/b6e4dbfc2ab853af2466e9545c6c273e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
[ | |
'title' => 'Nubank', | |
'amount' => 1455.73, | |
'due_date' => new \DateTime('01-11-2016'), | |
'tags' => [], | |
'paid' => true, | |
], | |
[ | |
'title' => 'Renner', | |
'amount' => 124.75, | |
'due_date' => new \DateTime('01-11-2016'), | |
'tags' => ['clothes'], | |
], | |
[ | |
'title' => 'Carro', | |
'amount' => 613, | |
'due_date' => new \DateTime('08-11-2016'), | |
'tags' => [], | |
], | |
[ | |
'title' => 'Aluguel', | |
'amount' => 1324.88, | |
'due_date' => new \DateTime('04-11-2016'), | |
'bar_code' => '03399.21199 54400.000227 79886.201023 1 69680000132488', | |
'tags' => ['friends'], | |
], | |
[ | |
'title' => 'Condomínio', | |
'amount' => 612.83, | |
'due_date' => new \DateTime('10-11-2016'), | |
'bar_code' => '08591.06098 10014.010408 00007.535016 2 69740000061284', | |
'tags' => ['friends'], | |
], | |
[ | |
'title' => 'Internet', | |
'amount' => 104.90, | |
'due_date' => new \DateTime('07-11-2016'), | |
'tags' => ['friends'], | |
], | |
[ | |
'title' => 'Luz', | |
'amount' => 225.69, | |
'bar_code' => '836800000025 256901620003 001010201620 348298677090', | |
'due_date' => new \DateTime('27-10-2016'), | |
'tags' => ['friends'], | |
], | |
]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"prelude/prelude": "dev-master" | |
}, | |
"repositories": [ | |
{ | |
"type": "vcs", | |
"url": "[email protected]:sergiors/prelude.git" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use const Prelude\{_, not, get, divide, sum}; | |
use function Prelude\{placeholder, pipe, filter, map, get, find, equals, join}; | |
require __DIR__.'/vendor/autoload.php'; | |
$bills = require __DIR__.'/bills.php'; | |
$findFriendsTag = pipe(placeholder(get, _, 'tags', []), find(equals('friends'))); | |
$filterFriends = filter($findFriendsTag); | |
$filterMy = filter(pipe($findFriendsTag, not)); | |
$filterPedding = filter(pipe(placeholder(get, _, 'paid', false), equals(false))); | |
$sumAmount = pipe(map(placeholder(get, _, 'amount', 0)), sum); | |
$fmtPerLine = map(function (array $bill) { | |
return get($bill, 'title', '').' - '.get($bill, 'amount', 0.0); | |
}); | |
$fmtBills = pipe($fmtPerLine, join("\n")); | |
$expensesFriends = pipe($filterFriends, $sumAmount); | |
$expensesPerFriend = pipe($expensesFriends, placeholder(divide, _, 3)); | |
$myExpensesSum = pipe($filterMy, $sumAmount); | |
echo pipe($filterMy, $filterPedding, $fmtBills)($bills), "\n", | |
pipe($filterPedding, $myExpensesSum)($bills), "\n"; | |
echo pipe($filterFriends, $fmtBills)($bills), "\n", | |
$expensesFriends($bills), "\n", | |
$expensesPerFriend($bills), "\n"; | |
/* | |
Renner - 124.750000 | |
Carro - 613.000000 | |
737.75 | |
Aluguel - 1324.880000 | |
Condomínio - 612.830000 | |
Internet - 104.900000 | |
Luz - 225.690000 | |
2268.3 | |
756.1 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment