From e3f195ca49aeadcff2c454e9c900b10f6909a6cc Mon Sep 17 00:00:00 2001 From: Zak Patterson Date: Tue, 5 Feb 2019 00:00:27 -0500 Subject: [PATCH] Add path extractor for extracting variables from urls --- .../src/main/scala/outwatch/router/Path.scala | 15 +++++++++++++++ project/Version.scala | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/outwatch-router/src/main/scala/outwatch/router/Path.scala b/outwatch-router/src/main/scala/outwatch/router/Path.scala index 8143656..c37997d 100644 --- a/outwatch-router/src/main/scala/outwatch/router/Path.scala +++ b/outwatch-router/src/main/scala/outwatch/router/Path.scala @@ -84,6 +84,21 @@ final case class /(parent: Path, child: String) extends Path { } } +/** + * Path separator extractor: + * {{{ + * Path("/1/2/3/test.json") match { + * case "1" /: "2" /: _ => ... + * }}} + */ +object /: { + def unapply(path: Path): Option[(String, Path)] = + path.toList match { + case head :: tail => Some(head -> Path(tail)) + case Nil => None + } +} + /** * Root extractor: * {{{ diff --git a/project/Version.scala b/project/Version.scala index 7836cb4..b8c3e67 100644 --- a/project/Version.scala +++ b/project/Version.scala @@ -1,4 +1,4 @@ object Version{ - val version = "0.0.1" + val version = "0.0.2" val scalaVersion = "2.12.8" }