Skip to content

Instantly share code, notes, and snippets.

@ubourdon
ubourdon / zio.scala
Last active October 13, 2024 16:17
utils function for navigate between scala Future, scalaz Task and scalaz ZIO
package service.utils
import scalaz.{-\/, \/, \/-}
import scalaz.zio.{DefaultRuntime, IO, ZIO}
import play.api.libs.concurrent.Execution.Implicits
import scalaz.concurrent.{Task => ZTask}
import scala.concurrent.{ExecutionContext, Future}
package object zio {
@ubourdon
ubourdon / DomainEventTypeclass.scala
Created November 20, 2018 14:09
"framework" de test pour système évènementiel en Scala
package domain
import domain.clientcompany.commands.ClientCompanyCommand
import domain.clientcompany.events.ClientCompanyEvent
import domain.clientcompany.models.{ClientCompanyError, ClientCompanyModel}
import domain.clientcompany.models.ClientCompanyModel.EmptyClientCompany
import domain.lot.commands.LotCommand
import domain.lot.events.LotEvent
import domain.lot.models.LotModel.EmptyLot
import domain.lot.models.{LotError, LotModel}
@ubourdon
ubourdon / DomainEventModule.hs
Last active November 21, 2018 14:28
Define and use multiparam typeclass
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FunctionalDependencies #-}
module Domain.UnoGame.DomainEventModule (DomainEventApply(..), DomainEventDecide(..), DomainEventEmptyState(..)) where
import Domain.UnoGame.Events.UnoGameEvents (UnoGameEvent)
import Domain.UnoGame.Commands.UnoGameCommands (UnoGameCommand)
import Domain.UnoGame.Models.UnoGameState (State(..))
import Domain.UnoGame.Events.UnoGameErrors (UnoGameError)
@ubourdon
ubourdon / newtype.scala
Last active July 30, 2018 09:32
Define newtype with smart constructor in scala
import scalaz.{@@, Show, Tag, \/}
import scalaz.Scalaz.ToEitherOps
/**
* Double représentant un pourcentage.
*/
package object percentagedouble {
private[percentagedouble] sealed trait PositiveOrNegativePercentageDoubleTag
type PositiveOrNegativePercentageDouble = Double @@ PositiveOrNegativePercentageDoubleTag
@ubourdon
ubourdon / NonEmptyListMaxSize.scala
Created March 22, 2018 16:27
Define non empty list with max size. newtype with smart constructor. Try to set the max size value at compile time
package domain.common.collection
import domain.common.number.strictpositiveint.StrictPositiveInt
import scalaz.Scalaz.ToEitherOps
import scalaz.{@@, NonEmptyList, Tag, \/}
object NonEmptyListMaxSize {
private[NonEmptyListMaxSize] sealed trait NonEmptyListMaxSize2Tag
type NonEmptyListMaxSize2[A] = NonEmptyList[A] @@ NonEmptyListMaxSize2Tag
@ubourdon
ubourdon / PositiveIntTest.scala
Created November 17, 2017 10:56
Define newtype in Scala. Example with positive Int.
import domain.common.number.positiveint.{InvalidRawValue, OperationError, PositiveInt}
import org.scalatest.{FunSuite, Matchers}
import scalaz.Scalaz.ToEitherOps
import PositiveInt.{IsEqual, IsHigher, IsLower, rawValue}
class PositiveIntTest extends FunSuite with Matchers {
test("PositiveInt should be positive") {
PositiveInt(-1) shouldBe InvalidRawValue("must be an integer > 0").left
PositiveInt(0) shouldBe InvalidRawValue("must be an integer > 0").left
@ubourdon
ubourdon / install-clever-tools.txt
Created February 22, 2017 14:41
nom install clever-tools
sudo npm install -g clever-tools
Password:
/Users/ugobourdon/.npm_install/bin/clever -> /Users/ugobourdon/.npm_install/lib/node_modules/clever-tools/bin/clever.js
/Users/ugobourdon/.npm_install/bin/install-clever-completion -> /Users/ugobourdon/.npm_install/lib/node_modules/clever-tools/scripts/install-autocomplete.sh
/Users/ugobourdon/.npm_install/bin/uninstall-clever-completion -> /Users/ugobourdon/.npm_install/lib/node_modules/clever-tools/scripts/uninstall-autocomplete.sh
> [email protected] install /Users/ugobourdon/.npm_install/lib/node_modules/clever-tools/node_modules/nodegit
> node lifecycleScripts/preinstall && node lifecycleScripts/install
[nodegit] Running pre-install script
@ubourdon
ubourdon / haskell_rule_evaluator.hs
Created January 11, 2017 16:20 — forked from fsarradin/haskell_rule_evaluator.hs
haskell_rule_evaluator
data BBool a b = BTrue a | BFalse b deriving (Show)
true :: a -> BBool a b
true a = BTrue a
trueMap :: (a -> b) -> BBool a c -> BBool b c
trueMap f (BTrue x) = BTrue (f x)
trueMap _ (BFalse x) = BFalse x
@ubourdon
ubourdon / Eventsourcing.txt
Created November 30, 2016 13:50
Qeestion sur l'eventsourcing
Règle métier externe à l'aggrégat. ex: nom d'utilisateur unique
Représentation d'évènements venu d'un système extérieur (ex: CallEmmittedTo ou SendingServiceOrderReported)
@ubourdon
ubourdon / Actions.txt
Last active November 17, 2016 16:47
Action Bouygues Anstel
Existant Anstel :
===============
1 patrimoine = 1 agence (fictive)
1 provider associé à 1 agence
Tickets associés au patrimoine
PB: 1 provider peut être (dans le cas métier) associé à plusieurs agences(= patrimoines)
CSQ : Sur saisie de tickets, provider non accessible pour action (assignation, ect...)