Skip to content

Instantly share code, notes, and snippets.

@jseteny
Last active February 23, 2022 18:55
Show Gist options
  • Save jseteny/da05ea9c55a192909475613049ab90a9 to your computer and use it in GitHub Desktop.
Save jseteny/da05ea9c55a192909475613049ab90a9 to your computer and use it in GitHub Desktop.
Handmade Shapeless. Naive, but functional and still succinct.
trait SList[T] {
def ::[H](head: H): ::[H, T] = new ::(head, this)
}
type SNil = Nothing
case object SNil extends SList[SNil]
case class ::[H, T](head: H, tail: SList[T]) extends SList[H :: T] {
override def toString = s"$head :: $tail"
}
println(
"A" :: 1 :: SNil
)
List(
"A" :: 1 :: SNil,
"B" :: 2 :: 3 :: SNil,
"C" :: "D" :: SNil
).foreach(slist => slist match {
case (s: String) :: (i: Int) :: _ =>
println(s"string: $s, than int: $i")
case a :: (b: String) :: _ =>
println(s"something: $a than string: $b")
})
case class Example(ds: Double :: String :: SNil)
val e = Example(2.72 :: "e" :: SNil)
println(e)
@jseteny
Copy link
Author

jseteny commented Feb 23, 2022

In the future I may implement a CSV converter using the CSV converter example from the original Shapeless:
https://github.com/milessabin/shapeless/blob/main/examples/src/main/scala/shapeless/examples/csv.scala
(This example shows how to createa a serializer/deserializer from CSV to products.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment