Coder Social home page Coder Social logo

metaphor's Introduction

Metaphor

Metaphor is a small library which leverages the parsing and generating capabilities of spray-json into a solution for the generation and extraction of Shapeless Records:

Shapeless provides an implementation of extensible records modelled as HLists of values tagged with the singleton types of their keys. This means that there is no concrete representation needed at all for the keys. Amongst other things this will allow subsequent work on Generic to map case classes directly to records with their member names encoded in their element types.

Usage

Usage of Metaphor is very straight forward. Generation is done by using the generate function, supplying the record and the appropriate fields to be serialised:

val person =
	("name" ->> "Barraco Barner") ::
	("occupation" ->> "President") ::
	("country" ->> "UK") ::
	("family" ->> List("Michello Barner, Miley Barner", "Sushi Barner")) ::
	HNil

val json = Metaphor.generate(person, "name", "occupation", "country", "family")

Depending on supplied record, the compiler will automagically detect if the fields are available in the record or not.

Extraction is done in a similar manner:

val js = """{"title": "Types and Programming Languages", "id": 262162091, "price": 44.11}""".asJson
val book = Metaphor.extract[String, Long, Float](js, "title", "id", "price")
book("title") == "Types and Programming Languages"

Extracting the appropriate types from the supplied JSON and generating a record with the same supplied field names.

Installation

Start by adding the repo:

"gideondk-repo" at "https://raw.github.com/gideondk/gideondk-mvn-repo/master"

to your SBT configuration and adding the package to your library dependencies:

libraryDependencies ++= Seq(
	"nl.gideondk" %% "metaphor" % "0.1.0"
)

License

Copyright © 2014 Gideon de Kok

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

metaphor's People

Contributors

gideondk avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.