Skip to content

Instantly share code, notes, and snippets.

@marcosh
marcosh / Country.php
Created Oct 15, 2020
Value object external validation
View Country.php
<?php
final class Country
{
private string $countryCode;
private function __construct(string $countryCode)
{
$this->countryCode = $countryCode;
}
View Apply.php
<?php
declare(strict_types=1);
/**
* @template F
* @template A
* @extends Functor<F,A>
*/
interface Apply extends Functor
@marcosh
marcosh / Boolean.php
Created Jan 16, 2020
Boolean implementation in PHP
View Boolean.php
<?php
declare(strict_types=1);
namespace Marcosh\PhpValidationDSL;
final class Boolean
{
/** @var Bool */
private $isTrue;
View WalkGraphsWithPairing.hs
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Graph where
import Control.Comonad
-- we need to separate `a` and `b` because `a` is covariant while `b` is contravariant => this is actually a profuctor
data PointedGraph moves b a = PointedGraph
View NamedTypeclass.hs
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module NamedTypeclass where
import Prelude hiding (Monoid, mempty, (<>))
@marcosh
marcosh / Application.hs
Created Jun 14, 2018
Web applications as profunctors
View Application.hs
module Application where
import Data.Profunctor
newtype Application request response = Application {unApplication :: request -> IO response}
instance Profunctor Application where
dimap actOnRequest actOnResponse application = Application $ (fmap actOnResponse) . (unApplication application) . actOnRequest
View recursion.md

Characterize recursable data structures

Recursion

Recursion is a procedure that allows us to iterate through certain data structure. For example we can iterate through lists

sum : List Nat -> Nat
sum list =
View proof on recursive step
module Hanoi
import Data.Vect
data Peg
= First
| Second
| Third
-- TODO : can we do better here?
View PDO FETCH_ASSOC vs PDO FETCH_FUNC
PDO::FETCH_FUNC without validation
10: 0.001568078994751
0.00071001052856445
0.00085306167602539
0.00087618827819824
0.00083112716674805
100: 0.0012631416320801
0.0014598369598389
View AddItemIntegrationTest.php
<?php
namespace MyTestNamespace;
//relevant use clauses
use ...
final class AddItemIntegrationTest extends \PHPUnit_Framework_TestCase
{
public function testAddItem()