Skip to content

Commit

Permalink
reactSelectPlus 0.1.1: add foldRaw extension method on SelectOption
Browse files Browse the repository at this point in the history
  • Loading branch information
nafg committed Dec 11, 2017
1 parent aee7b4c commit 7dff276
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ lazy val reactSelectPlus =
.enablePlugins(ScalaJSBundlerPlugin)
.settings(
basicSettings("react-select-plus", "1.0.0-rc.10.patch1"),
version := "0.1.0"
version := "0.1.1"
)

lazy val reactInputMask =
Expand Down
9 changes: 6 additions & 3 deletions reactSelectPlus/src/main/scala/reactselectplus/Select.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ object SelectOption {
}

implicit class ExtensionMethods[A](self: SelectOption[A]) {
def fold[T](groupF: Seq[SelectOption[A]] => T, dataF: (String, A) => T): T =
if (self.hasOwnProperty("options")) groupF(self.asInstanceOf[GroupSelectOption[A]].options)
def foldRaw[T](groupF: GroupSelectOption[A] => T, dataF: DataSelectOption[A] => T): T =
if (self.hasOwnProperty("options")) groupF(self.asInstanceOf[GroupSelectOption[A]])
else {
val data = self.asInstanceOf[DataSelectOption[A]]
dataF(data.value, data.data)
dataF(data)
}

def fold[T](groupF: Seq[SelectOption[A]] => T, dataF: (String, A) => T): T =
foldRaw(gso => groupF(gso.options), dso => dataF(dso.value, dso.data))
}
}

Expand Down

0 comments on commit 7dff276

Please sign in to comment.