This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {...}} | |
*/ |
NewerOlder