git clone git://github.com/mkoppanen/php-zmq.git
cd php-zmq
phpize && ./configure
make && make install
Finally add the following line to your php.ini:
| <?php | |
| // duck typing | |
| final class Foo { | |
| public function bar ($object) { | |
| $object->quack(); | |
| } | |
| } | |
| // Because we know nothing about $object, it's only by calling quack that we can | |
| // tell whether object supports quack() |
| <?php | |
| // method overloading example (not possible in php) | |
| final class SomeEventListener { | |
| public function when(EmployeeWasHired $event) { | |
| // set a salary | |
| } | |
| public function when(EmployeeWasPromoted $event) { | |
| // increase salary | |
| } |
| <?php | |
| final class Foo { | |
| public function bar (AnemicObject $object) { | |
| switch (true) { | |
| case $object instanceof Alfa: | |
| // do alpha shizzle | |
| case $object instanceof Beta: | |
| // do beta shizzle | |
| } |
| module MonoidalFizzBuzz where | |
| import Data.Monoid | |
| import Data.Maybe | |
| -- based on @mittie https://twitter.com/mittie/status/798257339736453120 | |
| monoidalFizzbuzz = zipWith fromMaybe numbers strings | |
| where | |
| fizzes = cycle [Nothing, Nothing, Just "Fizz"] | |
| buzzes = cycle [Nothing, Nothing, Nothing, Nothing, Just "Buzz"] |
| module Workflow where | |
| import Data.Maybe | |
| import Data.Set | |
| newtype State = State String deriving(Ord, Show, Eq) | |
| type States = Set State | |
| data Action = Action String deriving(Eq, Show) | |
| type Workflow = [Transition] | |
| data Transition = Transition { |
git clone git://github.com/mkoppanen/php-zmq.git
cd php-zmq
phpize && ./configure
make && make install
Finally add the following line to your php.ini:
| module Lib where | |
| import Data.List.Split | |
| import System.Random | |
| a4by4Maze :: Maze | |
| a4by4Maze = Maze [ | |
| [(╝),(╦),(╝),(╣)], | |
| [(╩),(╣),(╗),(╝)], | |
| [(═),(╩),(║),(╝)], |
| <?php | |
| final class FuckYouPHPTest extends \PHPUnit_Framework_TestCase { | |
| /** @test */ | |
| public function should_fail () { | |
| new WantsAString(new NotAString()); | |
| // Fails as expected | |
| } | |
| /** @test */ |
| {-# LANGUAGE ExistentialQuantification #-} | |
| module Beauforma where | |
| import qualified Data.Map.Strict as M | |
| data Event = | |
| GuestBookedAppointment { | |
| appointmentId :: Guid, | |
| guestId :: GuestId, | |
| appointmentDateAndTime :: DateTime, |
| {-# LANGUAGE ExistentialQuantification #-} | |
| module Money where | |
| data Money a = Currency a => Money {currency :: a, amount :: Float} | |
| instance Show (Money a) where | |
| show (Money c a) = show c ++ " " ++ show a | |
| instance Eq (Money a) where | |
| (Money cx x) == (Money cy y) = cx == cy && x == y | |
| class (Eq a, Show a) => Currency a where symbol :: a | |
| data EUR = EUR deriving (Show, Eq) |