Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object extractor {
- class Article(val header: String, val text: String, val footer: String)
- object Article {
- def unapply(obj: String): Option[(String, String, String)] = {
- val parts = obj.split("\n")
- if ( parts.length == 3) {
- Some(parts(0), parts(1), parts(2))
- } else {
- None
- }
- }
- }
- "My text\nIt is description.\nAuthor is me" match {
- case Article(h,t,f) => println(s"$h;$t;$f")
- case _ => println("None :( ")
- } //> My text;It is description.;Author is me
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement