Skip to content

Instantly share code, notes, and snippets.

fogfish

Block or report user

Report or block fogfish

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View text-query.ts
class Text {
static f(str: TemplateStringsArray, ...args: Array<any>) {
return <A>(...props: Array<A>): string => {
const parsed = args.map((x, index) => (typeof x === 'function' ? x(props[index]) : x))
if (parsed.some(x => x === undefined)) {
return ''
}
return str.reduce((acc, substr, index) => acc + this.text(parsed[index - 1]) + substr)
}
@fogfish
fogfish / aws-cdk-pure.ts
Last active Aug 8, 2019
defines pure functions to solve embarrassingly obvious composition problem in AWS CDK
View aws-cdk-pure.ts
//
// Copyright (C) 2019 Dmitry Kolesnikov
//
// This pure.ts file may be modified and distributed under the terms
// of the MIT license.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@fogfish
fogfish / HListMap.scala
Created May 4, 2018
Use Poly1 to Map HList
View HListMap.scala
import shapeless._
object size extends Poly1 {
implicit def default[T] = at[T](t => (t, 1))
implicit def caseInt = at[Int](x => (x, x))
implicit def caseString = at[String](s => (s, s.length))
}
@fogfish
fogfish / HListCodec.scala
Created May 4, 2018
Scala shapeless HList to Json with io.circe
View HListCodec.scala
import io.circe.{Encoder, JsonObject, ObjectEncoder}
import shapeless.{::, HList, HNil}
import scala.reflect.ClassTag
/**
* val product = A(...) :: B(...) :: C(...) :: HNil
* product.asJson
*
* {"a": {...}, "b": {...}, "c": {...}}
*/
You can’t perform that action at this time.