Skip to content

Instantly share code, notes, and snippets.

View RonanCamargo's full-sized avatar

Ronan Camargo RonanCamargo

View GitHub Profile
@RonanCamargo
RonanCamargo / IorErrorHandling.scala
Created November 24, 2021 01:52
Ior error handling
import cats.implicits._
import cats.data.Ior
case class Triangle(a: Double, b: Double, c: Double)
case class Error(message: String)
def validateSidesLength(input: Vector[Triangle]): Ior[Vector[Error], Vector[Triangle]] = {
val (errors, successfuls) = input.foldLeft((Vector.empty[Error], Vector.empty[Triangle])){
case ((errors, results), t@Triangle(a,b,c)) =>
if(a > 0 && b > 0 && c > 0) (errors, results :+ t)
@RonanCamargo
RonanCamargo / CaseClasses.scala
Last active November 24, 2021 02:44
Ior definition
case class Triangle(a: Double, b: Double, c: Double)
case class Error(message: String)
@RonanCamargo
RonanCamargo / di-in-fp.md
Created May 22, 2021 04:28 — forked from gvolpe/di-in-fp.md
Dependency Injection in Functional Programming

Dependency Injection in Functional Programming

There exist several DI frameworks / libraries in the Scala ecosystem. But the more functional code you write the more you'll realize there's no need to use any of them.

A few of the most claimed benefits are the following:

  • Dependency Injection.
  • Life cycle management.
  • Dependency graph rewriting.
@RonanCamargo
RonanCamargo / list_find
Created November 23, 2015 05:04
Ejemplo de list_find
tipoHuecoUtilizado* buscarHuecoPorPID(t_list* listaDeHuecosUtilizados,int pidProcesoBuscado){
tipoHuecoUtilizado* aux;
int pidBuscada(tipoHuecoUtilizado* huecoUtilizado){
return pidProcesoBuscado == huecoUtilizado->pid;
}
aux = list_find(listaDeHuecosUtilizados,pidBuscada);
return aux;
t_persona *crearPersona(char* nom,int ed){
t_persona *persona = malloc(sizeof(t_persona));
persona->nombre=nom;
persona->edad=ed;
return persona;
}
void destruirPersona(t_persona* persona){
free(persona->nombre);