Git Product home page Git Product logo

daniels-regex-interpreter's Introduction

Daniel's Regex Interpreter

An example application built from the ce3.g8 template.

Daniel Spiewak:palm_tree:  14 hours ago
Fun Scala Exercises (the first two work in any language; meant to be done in order)
Implement a regular expressions interpreter (ignore performance). I recommend implementing the following interface:
trait Regular {
  def |(that: Regular): Regular
  def ~(that: Regular): Regular
  def ? : Regular
  def + : Regular
  def apply(str: String): Boolean
}
object Regular {
  def apply(c: Char): Regular = ???
}
2. Ignoring stack-safety, make it purely functional (assuming you didn’t do so in step 1)
3. Adjust the apply method on Regular above to take an fs2 Stream[F, Char] instead of String. (hint: use Pull)
4. Optimize the performance of step 3 so that parsing a Chunk[Char] is just as fast as parsing a String was in step 2
5. Optimize the performance of step 4 so that there are zero allocations within a Chunk and all processing is stack-safe
The first step here is pretty easy. This increases in escalating difficulty. By the end of it, if you do it correctly, you have exercised everything you need to know in order to implement extremely high-performance FP on the JVM, and you've also learned a lot of advanced things about Fs2.
I'll post solutions sometime in the next few weeks when I get some time to sit down and do it. Have fun! (edited)

Oh also as a bonus round for extreme fun… After you finish the final step, revise it to make the whole thing run in O(n) (where n is the length of the string). It’s very likely that your implementation in all previous stages will be O(n^2), which is okay.

Run application

sbt run

Run tests

sbt test

daniels-regex-interpreter's People

Contributors

kubukoz 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.