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:
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 | |
} |
I hereby claim:
To claim this, I am signing this object:
def hello2Impl(c: blackbox.Context)(s: c.Expr[String]): c.Expr[Unit] = { | |
import c.universe._ | |
c.Expr(q"""println("hello " + ${s.tree} + "!")""") | |
} |
def hello2Impl(c: blackbox.Context)(s: c.Expr[String]): c.Expr[Unit] = { | |
import c.universe._ | |
c.Expr(q"""println("hello " + ${s.tree} + "!")""") | |
} |
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: |
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) |
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 { |
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) | |
} | |
} | |
import cats.instances.list._ | |
import Flatten.Level.Aux | |
import scala.language.higherKinds | |
object Flatten { | |
import cats.Monad | |
import cats.syntax.flatMap._ | |
trait Level { |
object OneWayImplicits { | |
//outside implicits visible, but T is not visible inside | |
case class Outwards[T](value: T) extends AnyVal | |
//outside implicits invisible, T is visible inside | |
case class Inwards[T](value: T) extends AnyVal | |
implicit def outwardsFromT[T](implicit t: T): Outwards[T] = Outwards(t) | |
implicit def tFromInwards[T](implicit inw: Inwards[T]): T = inw.value |