Skip to content

Instantly share code, notes, and snippets.

{
"Title":"Avengers: Infinity War",
"Year":"2018",
"Rated":"PG-13",
"ReleasedUSA":"23 Apr 2018",
"ReleasedIsrael":"26 Apr 2018",
"Runtime":"149 min",
"Genre":"Action, Adventure, Sci-Fi",
"Director":"Anthony Russo, Joe Russo",
@sankemax
sankemax / validator_example.kt
Last active April 17, 2020 18:49
An example of a simple validator pattern
import java.util.*;
data class Error(val reason: String, val path: String)
class Address(
val municipality: String,
val neighbourhood: String
)
abstract class Validator<T>(val toValidate: T) {
{
"Title":"{\"type\":\"string\",\"example\":\"Avengers: Infinity War\"}",
"Year":"{\"type\":\"string\",\"example\":\"2018\"}",
"Rated":"{\"type\":\"string\",\"example\":\"PG-13\"}",
"ReleasedUSA":"{\"type\":\"string\",\"example\":\"23 Apr 2018\"}",
"ReleasedIsrael":"{\"type\":\"string\",\"example\":\"26 Apr 2018\"}",
"Runtime":"{\"type\":\"string\",\"example\":\"149 min\"}",
"Genre":"{\"type\":\"string\",\"example\":\"Action, Adventure, Sci-Fi\"}",
"Director":"{\"type\":\"string\",\"example\":\"Anthony Russo, Joe Russo\"}",
"Writer":"{\"type\":\"string\",\"example\":\"Christopher Markus (screenplay by), Stephen McFeely (screenplay by), Stan Lee (based on the Marvel comics by), Jack Kirby (based on the Marvel comics by), Joe Simon (Captain America created by), Jack Kirby (Captain America created by), Steve Englehart (Star-Lord created by), Steve Gan (Star-Lord created by), Bill Mantlo (Rocket Raccoon created by), Keith Giffen (Rocket Raccoon created by), Jim Starlin (Thanos, Gamora a
{
"title":"{\"type\":\"string\",\"example\":\"Avengers: Infinity War\"}",
"year":"{\"type\":\"string\",\"example\":\"2018\"}",
"actors":[
"{\"type\":\"string\",\"example\":\"Robert Downey Jr.\"}"
],
"dates":{
"released":[
{
"usa":"{\"type\":\"string\",\"example\":\"2018-04-22T21:00:00.000Z\"}",
type Transform = {
source: string,
target: {
path: string,
priority?: number,
defaultValue?: any,
conditionalValue?: {
targetPathCondition: string,
value: any
}
import { Transform } from '@intelligo.ai/object-to-schema/dist/utils/types';
import response from './response.json';
import { mapObject } from '@intelligo.ai/object-to-schema';
const transformations: Transform[] = [
{
source: 'Title',
target: {
path: 'title'
}
{
"title":"Avengers: Infinity War",
"year":"2018",
"actors":[
"Robert Downey Jr.",
"Chris Hemsworth",
"Mark Ruffalo",
"Chris Evans"
],
"dates":{
{
"Title":"Avengers: Infinity War",
"Year":"2018",
"Rated":"PG-13",
"ReleasedUSA":"23 Apr 2018",
"ReleasedIsrael":"26 Apr 2018",
"Runtime":"149 min",
"Genre":"Action, Adventure, Sci-Fi",
"Director":"Anthony Russo, Joe Russo",
"Writer":"Christopher Markus (screenplay by), Stephen McFeely (screenplay by), Stan Lee (based on the Marvel comics by), Jack Kirby (based on the Marvel comics by), Joe Simon (Captain America created by), Jack Kirby (Captain America created by), Steve Englehart (Star-Lord created by), Steve Gan (Star-Lord created by), Bill Mantlo (Rocket Raccoon created by), Keith Giffen (Rocket Raccoon created by), Jim Starlin (Thanos, Gamora and Drax created by), Stan Lee (Groot created by), Larry Lieber (Groot created by), Jack Kirby (Groot created by), Steve Englehart (Mantis created by), Don Heck (Mantis created by)",
@sankemax
sankemax / Macro.md
Last active September 29, 2020 08:03

Macros are a feature that was introduced in Scala 2.10:

The motivation is to offload computations away from runtime when possible. If one has any knowledge about the execution of the code, presumably based on configuration or client code that won’t change, it would be beneficial to evaluate as much as possible during compile time.

Macros allow these evaluations. The result is called “expended code” that will be inlined at the place of the call to the macro after compilation.

I’ve used it for tracing (events going out to datadog):