scala - Can I use shapeless to return the same arity of HList as passed HList? -


here example. i'm trying wrap external api accepts , returns same arity of list:

def externapi(args: list[int]): list[string] = args.map(_.tostring) 

i thought excuse learn shapeless seems hlist able do.

def foo(args: hlist): hlist = ??? 

how can encode in type passed hlist , returned hlist of same arity?

to expand on @stew's comment, can use sized enforce equal arity between lists.

import shapeless._ import syntax.sized._  def externapi[n <: nat](args: sized[list[int], n]): sized[list[string], n] =     args.map(_.tostring) 

usage:

scala> externapi(sized[list](1, 2, 3, 4)) res0: shapeless.sized[list[string],shapeless.nat._4] = list(1, 2, 3, 4)  scala> res0 foreach println 1 2 3 4 

i'm far shapeless expert, don't know if there way hlist, seems collections homogeneous anyway.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -