Skip to content

Instantly share code, notes, and snippets.

View mantask's full-sized avatar

Mantas Kanaporis mantask

View GitHub Profile
@mantask
mantask / monads.kt
Last active November 1, 2022 21:04
Testing RiskEvaluationResult monad for composing multiple risk check functions
import java.math.BigDecimal
// Risk evaluation stuff
data class RiskEvaluation(
val status: Status,
val message: String? = null,
) {
enum class Status {
OK, WARN, FAIL,
@mantask
mantask / IdentityDocumentBuilder.kt
Created February 6, 2022 10:17
An example of functional composition for building a projection (ie data transfer object (DTO)).
import java.time.LocalDate
data class DocumentContext(
val personId: Long,
val userId: Long?,
)
interface Document
enum class DocumentType {
@mantask
mantask / 1_before.php
Last active August 29, 2015 13:59
Exception handling in PHP
<?php
/**
* Delete payment.
*/
public function delete($id)
{
$this->request->onlyAllow('post', 'delete');
$this->Payment->id = (int) $id;
$this->Payment->requireExists();
try {
@mantask
mantask / personal_number.php
Created October 18, 2013 11:44
Value Object for Lithuanian personal number.
<?php
class PersonalNumber
{
private $value;
// cached
private $age = null;
private $gender = null;
private $dateOfBirth = null;
private $isBlank = null;