-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Further simplify the codebase. Reduce redundancy and unnecessary abst…
…raction.
- Loading branch information
1 parent
e9974f0
commit c7bb453
Showing
13 changed files
with
157 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.scalawilliam.xs4s | ||
|
||
import javax.xml.stream.XMLEventReader | ||
import javax.xml.stream.events.XMLEvent | ||
|
||
import scala.xml.Elem | ||
|
||
/** | ||
* Created by me on 25/08/2016. | ||
*/ | ||
trait Implicits extends Scanner.Implicits { | ||
|
||
implicit class NodeSeqExtensions(nodeSeq: scala.xml.NodeSeq) { | ||
def ===(hasValue: String): Boolean = | ||
nodeSeq.text == hasValue | ||
|
||
def !==(notValue: String): Boolean = | ||
nodeSeq.text != notValue | ||
} | ||
|
||
implicit class RichXMLEventIterator(input: Iterator[XMLEvent]) { | ||
def buildXml: Iterator[XmlElementBuilder] = { | ||
input.scan(XmlElementBuilder.Scanner) | ||
} | ||
|
||
/** | ||
* Note this is unsafe. If the iterator is infinite then we'll never return. | ||
*/ | ||
def buildElement: Option[Elem] = { | ||
input.scanCollect(XmlElementBuilder.Scanner).toStream.lastOption | ||
} | ||
} | ||
|
||
implicit class RichXMLEventReader(eventReader: XMLEventReader) extends scala.collection.Iterator[XMLEvent] { | ||
def hasNext = eventReader.hasNext | ||
|
||
def next() = eventReader.nextEvent() | ||
|
||
def buildElement = eventReader.toIterator.buildElement | ||
} | ||
|
||
} | ||
|
||
object Implicits extends Implicits |
15 changes: 0 additions & 15 deletions
15
core/src/main/scala/com/scalawilliam/xs4s/NodeSeqExtensions.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.scalawilliam.xs4s | ||
|
||
/** | ||
* Created by me on 25/08/2016. | ||
*/ | ||
trait Scanner[In, State, Out] { | ||
def initial: State | ||
|
||
def scan(state: State, element: In): State | ||
|
||
def collect: PartialFunction[State, Out] | ||
} | ||
|
||
object Scanner { | ||
|
||
trait Implicits { | ||
|
||
implicit class RichIterator[T](iterator: Iterator[T]) { | ||
def scan[S, O](scanner: Scanner[T, S, O]): Iterator[S] = { | ||
iterator.scanLeft(scanner.initial)(scanner.scan) | ||
} | ||
|
||
def scanCollect[S, O](scanner: Scanner[T, S, O]): Iterator[O] = { | ||
iterator.scanLeft(scanner.initial)(scanner.scan).collect(scanner.collect) | ||
} | ||
} | ||
|
||
} | ||
|
||
object Implicits extends Implicits { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
core/src/main/scala/com/scalawilliam/xs4s/XmlEventIterator.scala
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
core/src/main/scala/com/scalawilliam/xs4s/elementbuilder/elementbuilder.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 17 additions & 15 deletions
32
...ain/scala/com/scalawilliam/xs4s/examples/ComputeBritainsRegionalMinimumParkingCosts.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.