mirror of
https://github.com/mcanlas/6502-opcodes.git
synced 2025-02-07 07:30:39 +00:00
paragraph demo
This commit is contained in:
parent
b2e21182d3
commit
178159f97e
5
data/two-paragraphs.txt
Normal file
5
data/two-paragraphs.txt
Normal file
@ -0,0 +1,5 @@
|
||||
foo
|
||||
bar
|
||||
|
||||
alpha
|
||||
bravo
|
@ -1,10 +1,6 @@
|
||||
package com.htmlism.firepower.demo
|
||||
|
||||
case class Line(s: String)
|
||||
|
||||
object Line:
|
||||
def mkString(xs: List[Line]): String =
|
||||
def mkString(xs: List[String]): String =
|
||||
xs
|
||||
.iterator
|
||||
.map(_.s)
|
||||
.mkString("\n")
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.htmlism.firepower.demo
|
||||
|
||||
/**
|
||||
* An abstraction for groups of lines that are eventually separated by newlines, but between paragraphs there's an
|
||||
* extra newline
|
||||
*/
|
||||
case class Paragraph(xs: List[String])
|
||||
|
||||
object Paragraph:
|
||||
val blankLine: Paragraph =
|
||||
Paragraph(List(""))
|
||||
|
||||
def apply(xs: String*): Paragraph =
|
||||
Paragraph(xs.toList)
|
||||
|
||||
def mkLines(ps: List[Paragraph]): List[String] =
|
||||
interlace(blankLine)(ps)
|
||||
.flatMap(_.xs)
|
||||
|
||||
private def interlace[A](x: A)(xs: List[A]): List[A] =
|
||||
xs match
|
||||
case head :: tail =>
|
||||
head :: tail.flatMap(a => List(x, a))
|
||||
|
||||
case Nil =>
|
||||
Nil
|
@ -13,9 +13,12 @@ object PrintPrograms extends ZIOAppDefault:
|
||||
|
||||
private val programs =
|
||||
List[(String, String)](
|
||||
"one-line.txt" -> "one line",
|
||||
"two-lines.txt" -> (Line.mkString _)
|
||||
.apply(List("foo", "bar").map(Line(_)))
|
||||
"one-line.txt" -> "one line",
|
||||
"two-lines.txt" -> (Line.mkString _)
|
||||
.apply(List("foo", "bar")),
|
||||
"two-paragraphs.txt" -> (Line.mkString _)
|
||||
.compose(Paragraph.mkLines)
|
||||
.apply(List(Paragraph("foo", "bar"), Paragraph("alpha", "bravo")))
|
||||
)
|
||||
|
||||
def run: Task[Unit] =
|
||||
|
Loading…
x
Reference in New Issue
Block a user