Skip to content

Instantly share code, notes, and snippets.

Loïc Descotte loicdescotte

Block or report user

Report or block loicdescotte

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
loicdescotte / App.scala
Last active Sep 3, 2019
Slinky React Hooks example
View App.scala
import slinky.web.html._
import slinky.core.facade.Hooks._
import slinky.core.FunctionalComponent
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
@JSImport("resources/App.css", JSImport.Default)
loicdescotte / accumulateErrors.scala
Last active Sep 30, 2019
Accumulate errors with Either and Cats (based on Cats documentation but with Error ADT and NonEmptyChain)
View accumulateErrors.scala
import cats.implicits._
import NonEmptyChain._
case class Name(value: String)
case class Age(value: Int)
case class Person(name: Name, age: Age)
trait Error
case object ParsingError extends Error
loicdescotte / fpmax.scala
Created Mar 3, 2019 — forked from jdegoes/fpmax.scala
FP to the Max — Code Examples
View fpmax.scala
package fpmax
import scala.util.Try
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
loicdescotte /
Created Jan 31, 2019
ReasonML : drop element in list
let dropListElement = (n, list) => {
let rec aux = (i, list) =>
switch list {
| [] => []
| [x, ...xs] => i == n ? xs : [x, ...aux(i + 1, xs)]
aux(0, list);
loicdescotte / compose.kt
Last active Jan 15, 2019
Compose errors (or nullables) and async functions in Scala, Kotlin, Typescript
View compose.kt
import arrow.core.Either
import arrow.core.Either.Companion.left
import arrow.core.Either.Companion.right
import arrow.core.Option
import arrow.core.Some
import arrow.core.flatMap
import arrow.instances.either.monad.binding
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
loicdescotte / EitherOps.scala
Last active Dec 17, 2018
Either ops to accumumate errors (and symmetric right method)
View EitherOps.scala
import scala.util._
implicit class EitherLeftOps[L](eithers: Seq[Either[L,_]]){
def collectLefts: Seq[L] = eithers.collect {
case Left(l) => l
implicit class EitherRightOps[R](eithers: Seq[Either[_,R]]){
def collectRights: Seq[R] = eithers.collect {
View catsSequenceFunctions.scala
import cats.implicits._
val f = (x: Int) => x+1
val g = (x: Int) => x+2
val h = (x: Int) => x+3
// Cats has an Applicative instance for Function1 so you can traverse/sequence it
val l = List(f, g, h).sequence //l : Function1[Int, List[Int]]
l(1) //List(2, 3, 4)
loicdescotte / kafkaClient.scala
Last active Oct 9, 2019
Kafka Client using Akka Streams and Avro4s
View kafkaClient.scala
import java.util.Properties
import akka.Done
import akka.kafka.scaladsl.Producer
import akka.kafka.{ProducerMessage, ProducerSettings}
import{Sink, Source}
import cats.effect.IO
import com.sksamuel.avro4s.{FromRecord, RecordFormat, ToRecord}
import org.apache.avro.generic.GenericRecord
loicdescotte / pipe.scala
Created Jul 13, 2018
Scala pipe function operator
View pipe.scala
implicit class AnyEx[T](val v: T) extends AnyVal {
def |>[U](f: T U): U = f(v)
def f(l: List[Int]) = l.filter(x => x >1)
def g(l: List[Int]) = l.filter(x => x <3)
List(1,2,3) |> f |> g //List(2)
loicdescotte / TaglessMonadError.scala
Last active Jul 10, 2018
Tagless final with MonadError
View TaglessMonadError.scala
import cats._
import cats.implicits._
def loadResult[F[_]](implicit F: MonadError[F, Throwable]): F[String] = {
val resultEitherF: F[Either[Throwable, String]] = ???
val resultF: F[String] = resultEitherF.flatMap(F.fromEither)
case error => F.pure(error.getMessage)
You can’t perform that action at this time.