Skip to content

Instantly share code, notes, and snippets.

import scala.annotation.tailrec
object FoldFun {
// Option
// List
// Vector
trait Foldable[F[_]]{ self =>
import cats.Monoid
import cats.Eval
import cats.Applicative
import cats.implicits._
import scala.annotation.tailrec
object TraverseDiscovery {
// trait Traverse[F[_]]{
// def traverse[G[_]: Applicative, A, B](fa: F[A])(f: A => G[B]): G[F[B]]
// }
def myTraverse[G[_]: Applicative, A, B](fa: List[A])(f: A => G[B]): G[List[B]] = {
import cats._
import cats.data._
import cats.implicits._
import cats.effect._
import scala.util.Try
object LoggingInPureFunctions {
// Writer[Vector[String], ?]
import cats._
import cats.data._
import cats.implicits._
object ValidateMyExistence {
// Say you are writing a password change application.
// You are given a username, an old password, and a new password
case class PasswordChangeRequest(username: String, oldPassword: String, newPassword: String)
// We have a set of rules we would like to enforce on this data,
// and would like to ensure that all of them are correct,
// example
private[service] def sendNelAlertsByPost(alerts: NonEmptyList[Alert], uri: Uri, client: Client): Task[List[Alert]] = {
val reqt: Task[Request] = POST(uri, alerts.toList.asJson)
val log: Task[Unit] = reqt.flatMap(req => req.bodyAsText.runLog.map(vs =>
req.toString + " body:" + vs.fold[String]("")(_ + _))
)
.flatMap(s => Task(println("**REQUEST**: " + s)))
val expect = client.expect(reqt)(jsonOf[List[Alert]])
log *> expect
}
trait Show[A] {
def show(a: A): String
}
object Show {
def apply[A](f: A => String): Show[A] = new Show[A] {
override def show(a: A): String = f(a)
"(.*)" should {
"(.*)" in ({.*\n.*\n.*\n.*\n.*\n.*\n })
}
find
--------------------------------------------------------------
replace
$1 should
$2 $eXXXX
case class DoSomething()
class ComputationActor extends Actor with Listeners {
def receive = listenerManagement orElse {
case DoSomething() = gossip(doSomething())
}
def doSomething(): Compuation = ???
}
@julianpeeters
julianpeeters / TwitterSourceConnector.java
Created April 12, 2016 19:37
How do Kafka configs work? Surprised that this fails. How can I avoid duplicating configs between the main app and the twitter connector?
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@julianpeeters
julianpeeters / test.avdl
Last active November 26, 2015 00:56 — forked from delagoya/test.avdl
Avro IDL comments to Avrodoc example 2
@namespace("com.example")
/**
This is a comment for the whole protocol
*/
protocol Example {
/**
The comment applies to the `NoSpaces` record, but is not indented to the