Skip to content

Instantly share code, notes, and snippets.

doi=10.1097%2F00125817-200001000-00001&doi=10.1097%2F00125817-200001000-00002&doi=10.1097%2F00125817-200001000-00003&doi=10.1097%2F00125817-200001000-00004&doi=10.1097%2F00125817-200001000-00005&doi=10.1097%2F00125817-200001000-00006&doi=10.1097%2F00125817-200001000-00007&doi=10.1097%2F00125817-200001000-00008&doi=10.1097%2F00125817-200001000-00009&doi=10.1097%2F00125817-200001000-00010&doi=10.1097%2F00125817-200001000-00011&doi=10.1097%2F00125817-200001000-00012&doi=10.1097%2F00125817-200001000-00013&doi=10.1097%2F00125817-200001000-00014&doi=10.1097%2F00125817-200001000-00015&doi=10.1097%2F00125817-200001000-00016&doi=10.1097%2F00125817-200001000-00017&doi=10.1097%2F00125817-200001000-00018&doi=10.1097%2F00125817-200001000-00019&doi=10.1097%2F00125817-200001000-00020&doi=10.1097%2F00125817-200001000-00021&doi=10.1097%2F00125817-200001000-00022&doi=10.1097%2F00125817-200001000-00023&doi=10.1097%2F00125817-200001000-00024&doi=10.1097%2F00125817-200001000-00025&doi=10.1097%2F00125817-200001000-00026&doi=10.109
sbt:contenthub-api> runtime:dependencyTree
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[warn] There may be incompatibilities among your library dependencies; run 'evicted' to see detailed eviction warnings.
[info] contenthub:contenthub-api-ontologies_2.12:LOCAL
[info] com.getsentry.raven:raven-logback:8.0.3
[info] +-ch.qos.logback:logback-classic:1.2.1 (evicted by: 1.2.3)
[info] +-ch.qos.logback:logback-classic:1.2.3
[info] | +-ch.qos.logback:logback-core:1.2.3
[info] | +-org.slf4j:slf4j-api:1.7.25 (evicted by: 1.7.28)
@scalolli
scalolli / Http4sMatchers.scala
Last active September 17, 2018 21:12
Http4s Matchers
import cats.effect.IO
import io.circe.{Decoder, Json}
import org.http4s.circe._
import org.http4s.{Response, Status}
import org.scalatest.EitherValues
import org.scalatest.matchers.{HavePropertyMatchResult, HavePropertyMatcher}
trait Http4sMatchers { this: EitherValues =>
def status(expected: Status) = HavePropertyMatcher { response: Response[IO] =>
HavePropertyMatchResult(matches = response.status == expected,
@scalolli
scalolli / ListApplicativeTests.hs
Created July 3, 2018 05:52
List Applicative Testing
module MyList where
import Data.Monoid
import Test.QuickCheck
import Test.QuickCheck.Classes
import Test.QuickCheck.Checkers
data List' a = Nil' | Cons' a (List' a) deriving (Eq, Show)
instance Monoid (List' a) where
@scalolli
scalolli / Compose.hs
Created June 27, 2018 06:03
How Haskell Compose works
λ> (\x -> Cons' x Nil') <$> (Just $ Right 5)
Just (Cons' (Right 5) Nil')
-- The whole reason of using Compose is acting as a type constructor, here we ended up making Just and Right part
-- of the Compose structure hence we only 5 is passed to the function (\x -> Cons' x Nil)
λ> (\x -> Cons' x Nil') <$> (Compose $ Just $ Right 5)
Compose (Just (Right (Cons' 5 Nil')))
@scalolli
scalolli / List.hs
Created June 26, 2018 05:31
List Traversable and Const Applicative
import Data.Monoid
data List' a = Nil' | Cons' a (List' a) deriving (Eq, Show)
instance Monoid (List' a) where
mempty = Nil'
mappend x Nil' = x
mappend Nil' x = x
mappend (Cons' a xs) ys = Cons' a $ xs <> ys
@scalolli
scalolli / Or.scala
Created June 20, 2018 19:25
ScalaCheckOr
sealed trait Or[A, B]
object Or {
case class FstA, B extends Or[A, B]
case class SndA, B extends Or[A, B]
}
implicit def eqOr[A: Eq, B: Eq]: Eq[Or[A, B]] = Eq.fromUniversalEquals
implicit def arbitraryOrA, B: Arbitrary[Gen[Or[A, B]]] = Arbitrary(
Gen.oneOf(Seq(Arbitrary.arbitrary[A].map(Fst()), Arbitrary.arbitrary[B].map(Snd())))
)
@scalolli
scalolli / EitherTravserse.scala
Created May 31, 2018 18:34
Either traverse cats
import cats.implicits._
def parseInt(s: String): Either[NumberFormatException, Int] = Either.catchOnly[NumberFormatException](s.toInt)
List("1", "2", "3").traverse(parseInt)
@scalolli
scalolli / FunctionComposition.hs
Last active May 31, 2018 06:23
Functor and Applicatives for Functions
fmap (*2) (+1) $ 1
so that returns 4
But why can I not do
(fmap (*2) (+)) 1 2 ?
@scalolli
scalolli / CustomArbitrary.hs
Created May 4, 2018 05:51
Writing arbitrary
-- Functor for Company a b c
data Company a b c = DeepBlue a c | Something b deriving (Eq, Show)
instance Functor (Company a b) where
fmap f (DeepBlue a c) = DeepBlue a (f c)
fmap f (Something b) = Something b
instance (Arbitrary a, Arbitrary b, Arbitrary c) => Arbitrary (Company a b c) where
arbitrary = do