Skip to content

Instantly share code, notes, and snippets.

Avatar
😱
I might take a week to respond. Or a month.

Jakub Kozłowski kubukoz

😱
I might take a week to respond. Or a month.
View GitHub Profile
View Matrix.scala
package com.kubukoz.polskibus.domain
import scala.language.postfixOps
case class Matrix[T](data: List[T]*)(implicit ev1: Numeric[T]) {
final lazy val valid = {
require(data.forall(s => s.size == data.head.size), "All rows must have the same column amount")
true
}
View keybase.md

Keybase proof

I hereby claim:

  • I am kubukoz on github.
  • I am kubukoz (https://keybase.io/kubukoz) on keybase.
  • I have a public key whose fingerprint is 64B8 07A1 F72B 7C70 7215 E52F CE45 291D 373C EC29

To claim this, I am signing this object:

View gist:0b723779d32da110e8e7
def hello2Impl(c: blackbox.Context)(s: c.Expr[String]): c.Expr[Unit] = {
import c.universe._
c.Expr(q"""println("hello " + ${s.tree} + "!")""")
}
View Hello2Quasi.scala
def hello2Impl(c: blackbox.Context)(s: c.Expr[String]): c.Expr[Unit] = {
import c.universe._
c.Expr(q"""println("hello " + ${s.tree} + "!")""")
}
View histogram.kt
fun <T> List<T>.histogram(map: (T) -> Int, showAs: (Boolean, T) -> String): String {
val maxHeight = map { map(it) }.max() ?: 0
return (maxHeight downTo 0).map { i ->
this.map {
showAs(i <= map(it), it)
}.joinToString("")
}.joinToString("\n")
}
//Sample usage:
View ComposedFunctors.scala
import scala.concurrent.Future
import scala.language.higherKinds
import scalaz.Functor
/**
* Created by kubukoz on 25/01/2017.
*/
object ComposedFunctors {
implicit class ComposedMapOps[F[_], G[_], T](val functor: F[G[T]]) extends AnyVal {
View Flatten.scala
import cats.instances.list._
import Flatten.Level.Aux
import scala.language.higherKinds
object Flatten {
import cats.Monad
import cats.syntax.flatMap._
trait Level {
View ValidationTraverseOps.scala
import scala.language.higherKinds
import scalaz.{Semigroup, Traverse, Validation}
object ValidationTraverseOps {
implicit class ValidationTraverseOps[G[_], T](val gt: G[T]) extends AnyVal {
def traverseRight[U, E : Semigroup](fun: T => Validation[E, U])(implicit traverseG: Traverse[G]): Validation[E, G[U]] = {
traverseG.traverse[({type L[TT] = Validation[E, TT]})#L, T, U](gt)(fun)
}
}
@kubukoz
kubukoz / GroupToNel.scala
Last active Jul 12, 2017
A `groupBy` implementation in which the result's values are guaranteed not to be empty on the type level.
View GroupToNel.scala
import scalaz.{Foldable, NonEmptyList}
import scalaz.syntax.foldable._
implicit class GroupToNel[F[_] : Foldable, T](foldable: F[T]){
def groupToNel[K](fun: T => K): Map[K, NonEmptyList[T]] = {
f.foldLeft(Map.empty[K, NonEmptyList[T]]) { (map, elem) =>
val funOfElem = fun(elem)
val newValue = map.get(funOfElem).fold(NonEmptyList(elem))(list => elem <:: list)
View ChainedConversions.scala
object ChainedConversions {
implicit def chain[A, B, C](implicit ab: A => B, bc: B => C): A => C = ab andThen bc
implicit val intToString: Int => String = _.toString
class X
implicit val stringToX: String => X = _ => new X
val a: X = 5 // idea marks it as a proper conversion
//doesn't compile though
}