Giter VIP home page Giter VIP logo

spata's People

Contributors

gitter-badger avatar sjrd avatar susuro avatar zrogezrg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

spata's Issues

Expose methods that render to Stream[F, String]

Rendering a CSV for consumption via http4s requires a Stream[F, Byte]. However, the current API only exposes a render method that builds Stream[F, Char]. The only safe way to convert that to Byte is to do something like:

.render
.through(fs2.text.char2string)
.through(fs2.text.utf8.encode)

Can we refactor this to expose a renderString method. We already have a Stream[String] up to the last line but then convert to chars.

  def render: Pipe[F, Record, Char] = (in: Stream[F, Record]) =>
    def loop(in: Stream[F, Record], header: Header): Pull[F, Either[HeaderError, String], Unit] =
      in.pull.uncons.flatMap:
        case Some((rc, t)) => Pull.output(rc.map(renderRow(_, header))) >> loop(t, header)
        case None => Pull.done
    val pull = in.pull.uncons1.flatMap:
      case Some((r, t)) =>
        val headerRow = if config.hasHeader then Pull.output1(renderHeader(r.header)) else Pull.pure(())
        val firstRow = Pull.output1(renderRow(r, r.header))
        headerRow >> firstRow >> loop(t, r.header)
      case None => Pull.done
    pull.stream.through(toChars)

  private def toChars: Pipe[F, EHE[String], Char] = (in: Stream[F, EHE[String]]) =>
    in.rethrow
      .intersperse(srd)
      .map(s => Chunk.array[Char](s.toCharArray))
      .flatMap(Stream.chunk)

Header re-mapping doesn't work for renderer

Header mapping, set through CSVConfig.mapHeader is ignored by CSVRenderer (although it works forCSVParser).
Regardless of the new names provided through mapHeader, the actual CSV file has the original header (set directly or obtained from the first record). E.g. for the snippet in readme.md:

val stream: Stream[IO, Record] = ???
val renderer: CSVRenderer[IO] =
  CSVRenderer.config.mapHeader(Map("tempMax" -> "max temparature", "tempMin" -> "min temparature")).renderer[IO]
val frosty: Stream[IO, Char] = stream.filter(_.get[Double]("minTemp").exists(_ < 0)).through(renderer.render)

the resulting header is

tempMax;tempMin

instead of

max temperature;min temperature

fs2-3 and cats-effect-3

Hello! Was just wondering if there were plans to publish versions for fs2-3.x.x and cats-effect-3, or if contributions would be welcome for the same. We're migrating our systems and spata is one of our last holdouts.

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.