casual currying
Dec. 1st, 2014 04:54 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
no oop
I wanted this:
But has to write this:
Using it like this:
I wanted this:
def from(location: String) = { def loadTable(name: String, ignoring: String*) { def ignoringColumns(row: String Map String) = row.filterKeys(k => !(ignoring contains k)) val src = Source.fromFile(s"$location/$name.csv").getLines().mkString("\n") val data = parseText(src) map ignoringColumns insertInto(name, data) } }
But has to write this:
case class from(location: String) { self => def loadTable(name: String, ignoring: String*): from = { // actually, the load order is opposite to deletion order update(s"delete from $name") def ignoringColumns(row: String Map String) = row.filterKeys(k => !(ignoring contains k)) val src = Source.fromFile(s"$location/$name.csv").getLines().mkString("\n") val data = parseText(src) map ignoringColumns toList insertInto(name, data) self } }
Using it like this:
from(location). loadTable("users"). loadTable("abusers","historyOfAbuse"). loadTable("WMD","rocks","stones"). loadTable("passwordAndKeys")
no subject
Date: 2014-12-02 09:50 am (UTC)Операторы больше одной строки должны быть запрещены.
no subject
Date: 2014-12-02 11:10 am (UTC)no subject
Date: 2014-12-02 11:17 am (UTC)no subject
Date: 2014-12-02 02:55 pm (UTC)no subject
Date: 2014-12-02 03:06 pm (UTC)