scala - How to invoke function of multiple arguments with HList? -


suppose have hlist of type a::b::c::hnil , function (a, b, c) => d

val hlist: a::b::c::hnil = ??? def foo(a: a, b: b, c: c): d = ??? 

now need funciton a::b::c::hnil => d, uses foo return d.

def bar(hslist: a::b::c::hnil): d = ??? 

how implement bar ?

you can little more directly using shapeless's fntoproduct, provides toproduct syntax converting functionn function1 taking hlist:

import shapeless._, syntax.std.function._  type = string type b = symbol type c = int type d = list[string]  val hlist: :: b :: c :: hnil = "foo" :: 'x :: 1 :: hnil  def foo(a: a, b: b, c: c): d = list.fill(c)(a + b)  def bar(hslist: :: b :: c :: hnil): d = (foo _).toproduct.apply(hslist) 

in many cases wouldn't want separate bar definition.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -