juan_gandhi: (VP)
[personal profile] juan_gandhi
no oop

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")

Date: 2014-12-02 09:50 am (UTC)
From: [identity profile] andybil.livejournal.com
Очень распространённая "невидимая" ошибка.
Операторы больше одной строки должны быть запрещены.
Edited Date: 2014-12-02 09:52 am (UTC)

Date: 2014-12-02 11:10 am (UTC)
From: [identity profile] juan-gandhi.livejournal.com
Кто должен это запретить? (Маяковский?)

Date: 2014-12-02 11:17 am (UTC)
From: [identity profile] andybil.livejournal.com
Попробуйте разрушить гору одним камушком. А вашу программу одной буквой запросто. Это и есть главный критерий выбора языка программирования.ОДнако среди текущих таких нету.
Edited Date: 2014-12-02 11:25 am (UTC)

Date: 2014-12-02 02:55 pm (UTC)
From: [identity profile] sassa-nf.livejournal.com
";" - это тоже оператор.

Date: 2014-12-02 03:06 pm (UTC)
From: [identity profile] andybil.livejournal.com
http://ivan-gandhi.livejournal.com/2981102.html?thread=45994734#t45994734

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

July 2025

S M T W T F S
  12345
6789 1011 12
13141516171819
20212223242526
2728293031  

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 13th, 2025 02:49 am
Powered by Dreamwidth Studios