Giter Site home page Giter Site logo

gencodec's Introduction

gencodec

gencodec is a tool to quickly generate Circe encoders/decoders, inspired by Mr. Boilerplate.

Installation

You can download a binary from the Github releases page (macOS only at the moment), or build it yourself with Cargo.

Usage

gencodec accepts via stdin a line that contains a case class description (something like case class Something(number: Int, whatever: String)) and prints to stdout a companion object for that case class, along with a Circe Encoder and Decoder defined using the forProductN methods. For the given example, it would be

object Something {
  implicit lazy val encoder: Encoder[Something] = Encoder.forProduct2("number", "whatever")(a => (a.number, a.whatever))

  implicit lazy val decoder: Decoder[Something] = Decoder.forProduct2("number", "whatever")(Something.apply)
}

That's all it does!

Integration

Used directly from the command-line, this wouldn't be that useful and Mr. Boilerplate would probably be better. I wrote gencodec specifically for the use-case of directly generating encoders and decoders from within Vim. You can put something like this in your ftplugin/scala.vim file:

function! GenCodec() range
  let input = shellescape(join(getline(a:firstline, a:lastline), ""))
  let output = extend([""], split(system('echo '.input.' | gencodec'), "\n"))
  call append(a:lastline, output)
endfunction

command! -range=% -nargs=0 GenCodec :<line1>,<line2>call GenCodec()

Then, you can select a case class definition in visual mode (it can span multiple lines) and run :GenCodec, at which point the generated companion object will be inserted after the selected range.

Demonstration of Vim integration

License

Licensed under either of

at your option.

gencodec's People

Contributors

ktfleming avatar

Stargazers

 avatar

Watchers

 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.