Skip to content

Instantly share code, notes, and snippets.

no_funs({M, _}) ->
{M,length(M:module_info(exports))}.
max_funs({Lm,Lsize},{Rm,Rsize}) ->
case Lsize =< Rsize of
true -> {Rm,Rsize};
false -> {Lm,Lsize}
end.
largest_module(Modules) ->
@richard-gibson
richard-gibson / MagnetExample.scala
Created June 14, 2015 23:40
Simple magnet example
object MagnetExample extends App {
sealed trait AdditionMagnet {
type Result
def apply():Result
}
object AdditionMagnet {
@richard-gibson
richard-gibson / mult-github-accounts.md
Created December 16, 2015 09:44
ssh config and usage for multiple github accounts

Add to ~/.ssh/config

Host github.com-foo
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_foo

Host github.com-bar
 HostName github.com
val examinePattern: (String, String, String) => String = {
case (pattern, "", _) => pattern
case (pattern, tail, orig) if tail.take(pattern.length) == pattern =>
examinePattern(pattern, tail.drop(pattern.length), orig)
case (pattern, _, orig) =>
examinePattern(orig.take(pattern.length + 1), orig, orig)
}
val runEp : String => String =
import scala.reflect.ClassTag
//ClassTag will make type info available that is erased by the JVM at runtime
def filterT[T :ClassTag](t:Any) : Boolean = t match {
case _:T => true
case _ => false
}
val anyL = List(1,"fe", 2, 3, 'a')

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@richard-gibson
richard-gibson / gist:61596733a7cb65bd75139b5eabe4e36c
Created October 25, 2018 21:57
Arrow Either Validation examples
package co.brightcog.validation
import arrow.core.*
import arrow.data.*
import arrow.typeclasses.*
sealed class Failure {
data class EmptyString(val fieldName: String) : Failure()
data class InvalidCity(val fieldName: String) : Failure()
[error] /.../src/test/scala/admin/repository/ProductServiceSqlTest.scala:18:14: type mismatch;
[error] found : cats.effect.Resource[cats.effect.IO,doobie.hikari.HikariTransactor[cats.effect.IO]]
[error] (which expands to) cats.effect.Resource[cats.effect.IO,doobie.util.transactor.Transactor[cats.effect.IO]{type A = com.zaxxer.hikari.HikariDataSource}]
[error] required: cats.effect.Resource[F,doobie.hikari.HikariTransactor[F]]
[error] (which expands to) cats.effect.Resource[F,doobie.util.transactor.Transactor[F]{type A = com.zaxxer.hikari.HikariDataSource}]
[error] xa <- transactor(dbConf)
[error] ^
[info] cats.effect.Resource[cats.effect.IO,doobie.hikari.HikariTransactor[cats.effect.IO]] <: cats.effect.Resource[F,doobie.hikari.HikariTransactor[F]]?
[info] F[_] <: cats.effect.IO[_]?
[info] false

I've been working with Kafka for over 7 years. I inevitably find myself doing the same set of activities while I'm developing or working with someone else's system. Here's a set of Kafka productivity hacks for doing a few things way faster than you're probably doing them now. 🔥

Get the tools

@richard-gibson
richard-gibson / multiProducerMultiConsumerQueue.kt
Created October 20, 2019 19:51
Example of multiple producers using a single Arrow Effects Queue
import arrow.Kind
import arrow.core.Either
import arrow.fx.IO
import arrow.fx.ForIO
import arrow.fx.Queue
import arrow.fx.Timer
import arrow.fx.fix
import arrow.fx.handleErrorWith
import arrow.fx.QueueShutdown
import arrow.fx.extensions.fx