Function that retrieves element from HList (while preserving its type)
up vote
0
down vote
favorite
I have this type which will be generated via shapeless:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Basically I have a bunch of case objects extending a trait so I managed to create a method which gives me instances of all case objects as an HList
Then using import shapeless.ops.hlist.Last and init I wrote a method to retrieve one of the nodes in the HList if the value is equal to the string "student":
def getLast(hl:hlistt) = {
val last0=Last[hlistt]
val la=last0(hl)
if (la.value == "student") la
else init(hl)
}
The issue is that if I call this method I will not get the correct node type from the HList.
getLast(STUDENT :: AUTO_LOANS :: HNil)
The method works and returns the node but the type is off:
Product with Serializable = STUDENT :: HNil
Do I need some Witness/Aux implicits to return the correct type?
scala shapeless hlist
add a comment |
up vote
0
down vote
favorite
I have this type which will be generated via shapeless:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Basically I have a bunch of case objects extending a trait so I managed to create a method which gives me instances of all case objects as an HList
Then using import shapeless.ops.hlist.Last and init I wrote a method to retrieve one of the nodes in the HList if the value is equal to the string "student":
def getLast(hl:hlistt) = {
val last0=Last[hlistt]
val la=last0(hl)
if (la.value == "student") la
else init(hl)
}
The issue is that if I call this method I will not get the correct node type from the HList.
getLast(STUDENT :: AUTO_LOANS :: HNil)
The method works and returns the node but the type is off:
Product with Serializable = STUDENT :: HNil
Do I need some Witness/Aux implicits to return the correct type?
scala shapeless hlist
1
That's not the correct code to reproduce the result you describe. For one thing,getLast(), as posted, is not recursive.
– jwvh
Nov 20 at 9:00
@jwvh good point - I wrote this late at night (my time) and initially was thinking of a recursive fn. I did mean to wrapinit(hl)intogetLast(init(hl))
– Adrian
Nov 20 at 17:47
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have this type which will be generated via shapeless:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Basically I have a bunch of case objects extending a trait so I managed to create a method which gives me instances of all case objects as an HList
Then using import shapeless.ops.hlist.Last and init I wrote a method to retrieve one of the nodes in the HList if the value is equal to the string "student":
def getLast(hl:hlistt) = {
val last0=Last[hlistt]
val la=last0(hl)
if (la.value == "student") la
else init(hl)
}
The issue is that if I call this method I will not get the correct node type from the HList.
getLast(STUDENT :: AUTO_LOANS :: HNil)
The method works and returns the node but the type is off:
Product with Serializable = STUDENT :: HNil
Do I need some Witness/Aux implicits to return the correct type?
scala shapeless hlist
I have this type which will be generated via shapeless:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Basically I have a bunch of case objects extending a trait so I managed to create a method which gives me instances of all case objects as an HList
Then using import shapeless.ops.hlist.Last and init I wrote a method to retrieve one of the nodes in the HList if the value is equal to the string "student":
def getLast(hl:hlistt) = {
val last0=Last[hlistt]
val la=last0(hl)
if (la.value == "student") la
else init(hl)
}
The issue is that if I call this method I will not get the correct node type from the HList.
getLast(STUDENT :: AUTO_LOANS :: HNil)
The method works and returns the node but the type is off:
Product with Serializable = STUDENT :: HNil
Do I need some Witness/Aux implicits to return the correct type?
scala shapeless hlist
scala shapeless hlist
edited Nov 20 at 17:46
asked Nov 20 at 7:34
Adrian
3,88063869
3,88063869
1
That's not the correct code to reproduce the result you describe. For one thing,getLast(), as posted, is not recursive.
– jwvh
Nov 20 at 9:00
@jwvh good point - I wrote this late at night (my time) and initially was thinking of a recursive fn. I did mean to wrapinit(hl)intogetLast(init(hl))
– Adrian
Nov 20 at 17:47
add a comment |
1
That's not the correct code to reproduce the result you describe. For one thing,getLast(), as posted, is not recursive.
– jwvh
Nov 20 at 9:00
@jwvh good point - I wrote this late at night (my time) and initially was thinking of a recursive fn. I did mean to wrapinit(hl)intogetLast(init(hl))
– Adrian
Nov 20 at 17:47
1
1
That's not the correct code to reproduce the result you describe. For one thing,
getLast(), as posted, is not recursive.– jwvh
Nov 20 at 9:00
That's not the correct code to reproduce the result you describe. For one thing,
getLast(), as posted, is not recursive.– jwvh
Nov 20 at 9:00
@jwvh good point - I wrote this late at night (my time) and initially was thinking of a recursive fn. I did mean to wrap
init(hl) into getLast(init(hl))– Adrian
Nov 20 at 17:47
@jwvh good point - I wrote this late at night (my time) and initially was thinking of a recursive fn. I did mean to wrap
init(hl) into getLast(init(hl))– Adrian
Nov 20 at 17:47
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
la is of type AUTO_LOANS.type, init(hl) is of type STUDENT.type :: HNil, so
if (la.value == "student") la
else init(hl)
is of type Any (or Product with Serializable).
If you would like to return values of different types from different branches you need a Poly.
import shapeless.{Poly1, Witness}
object myPoly extends Poly1 {
implicit def studentCase: Case.Aux[Witness.`"student"`.T, STUDENT.type] =
at(_ => STUDENT)
implicit def autoLoansCase: Case.Aux[Witness.`"auto-loans"`.T, AUTO_LOANS.type] =
at(_ => AUTO_LOANS)
}
import shapeless.syntax.singleton._
println(
myPoly("student".narrow)
) // STUDENT
println(
myPoly("auto-loans".narrow)
) // AUTO_LOANS
// println(
// myPoly("abc".narrow)
// ) // doesn't compile
This approach works if the string is known at compile time.
add a comment |
up vote
1
down vote
I am not quite sure what you want to do. Given:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Last[hlistt] will resolve to AUTO_LOANS.type (your true if branch)
while init will resolve to STUDENT :: HNil (your false if branch)
the LUB (least upper bound) of these types will be Product with Serializable so that's why you see that.
If you want to check a runtime property of a member of the hlist you'll have to thread the appropriate typebounds and result types through by deriving them with the appropriate machinery. In this case that is already given by shapeless.
https://scalafiddle.io/sf/fdtn3cz/0
Is this what you wanted?
EDIT:
I also just read
I have this type which will be generated dynamically:
what do you exactly mean by "dynamically"? because unless you can specify some compile time properties, shapeless might not be the solution you're looking for.
You got very close to what I want. Do you know why I can't do:if(last(hlist).value == "student") Some(last(hlist)) else getLastOrNone(init(hlist))and adding a case forHNil. I get a type mismatch. I'm trying to traverse the HList and do a find node by value instead of by type.
– Adrian
Nov 20 at 17:40
the problem with that is that you won't know at compile time what the output type of your function is because it depends on runtime values. What is your motivation to useHList?
– Dominic Egger
Nov 20 at 17:53
I want to preserve the types ofCarandStudentin your sample code. The actual problem I'm having is given a string "student" or "car" get the correct singleton ie Student or Car. I have type classes defined on these singleton types which is why I'm trying really hard to preserve types. I'm also looking into making some mapping of "car"->Car,"student"->Student so when I'm given a text I can use it as a key to get the appropriate type
– Adrian
Nov 20 at 18:29
1
well technically I guess you could formulate a function that goes from some hlistA :: B :: C :: HNiltoA :+: B :+: C :+: Unit :+: CNiland finds the first match for some predicate poly-function or returnsUnit. But because you base this off runtime values I don't think you can do it directly. what would the returntype of that function be? so it'd go more towards a solution as Dmytro said bellow.
– Dominic Egger
Nov 20 at 18:47
Ya that's my roadblock: don't know what the type of that method would be :(
– Adrian
Nov 20 at 18:55
|
show 1 more comment
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
la is of type AUTO_LOANS.type, init(hl) is of type STUDENT.type :: HNil, so
if (la.value == "student") la
else init(hl)
is of type Any (or Product with Serializable).
If you would like to return values of different types from different branches you need a Poly.
import shapeless.{Poly1, Witness}
object myPoly extends Poly1 {
implicit def studentCase: Case.Aux[Witness.`"student"`.T, STUDENT.type] =
at(_ => STUDENT)
implicit def autoLoansCase: Case.Aux[Witness.`"auto-loans"`.T, AUTO_LOANS.type] =
at(_ => AUTO_LOANS)
}
import shapeless.syntax.singleton._
println(
myPoly("student".narrow)
) // STUDENT
println(
myPoly("auto-loans".narrow)
) // AUTO_LOANS
// println(
// myPoly("abc".narrow)
// ) // doesn't compile
This approach works if the string is known at compile time.
add a comment |
up vote
1
down vote
accepted
la is of type AUTO_LOANS.type, init(hl) is of type STUDENT.type :: HNil, so
if (la.value == "student") la
else init(hl)
is of type Any (or Product with Serializable).
If you would like to return values of different types from different branches you need a Poly.
import shapeless.{Poly1, Witness}
object myPoly extends Poly1 {
implicit def studentCase: Case.Aux[Witness.`"student"`.T, STUDENT.type] =
at(_ => STUDENT)
implicit def autoLoansCase: Case.Aux[Witness.`"auto-loans"`.T, AUTO_LOANS.type] =
at(_ => AUTO_LOANS)
}
import shapeless.syntax.singleton._
println(
myPoly("student".narrow)
) // STUDENT
println(
myPoly("auto-loans".narrow)
) // AUTO_LOANS
// println(
// myPoly("abc".narrow)
// ) // doesn't compile
This approach works if the string is known at compile time.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
la is of type AUTO_LOANS.type, init(hl) is of type STUDENT.type :: HNil, so
if (la.value == "student") la
else init(hl)
is of type Any (or Product with Serializable).
If you would like to return values of different types from different branches you need a Poly.
import shapeless.{Poly1, Witness}
object myPoly extends Poly1 {
implicit def studentCase: Case.Aux[Witness.`"student"`.T, STUDENT.type] =
at(_ => STUDENT)
implicit def autoLoansCase: Case.Aux[Witness.`"auto-loans"`.T, AUTO_LOANS.type] =
at(_ => AUTO_LOANS)
}
import shapeless.syntax.singleton._
println(
myPoly("student".narrow)
) // STUDENT
println(
myPoly("auto-loans".narrow)
) // AUTO_LOANS
// println(
// myPoly("abc".narrow)
// ) // doesn't compile
This approach works if the string is known at compile time.
la is of type AUTO_LOANS.type, init(hl) is of type STUDENT.type :: HNil, so
if (la.value == "student") la
else init(hl)
is of type Any (or Product with Serializable).
If you would like to return values of different types from different branches you need a Poly.
import shapeless.{Poly1, Witness}
object myPoly extends Poly1 {
implicit def studentCase: Case.Aux[Witness.`"student"`.T, STUDENT.type] =
at(_ => STUDENT)
implicit def autoLoansCase: Case.Aux[Witness.`"auto-loans"`.T, AUTO_LOANS.type] =
at(_ => AUTO_LOANS)
}
import shapeless.syntax.singleton._
println(
myPoly("student".narrow)
) // STUDENT
println(
myPoly("auto-loans".narrow)
) // AUTO_LOANS
// println(
// myPoly("abc".narrow)
// ) // doesn't compile
This approach works if the string is known at compile time.
edited Nov 20 at 10:14
answered Nov 20 at 10:05
Dmytro Mitin
6,146515
6,146515
add a comment |
add a comment |
up vote
1
down vote
I am not quite sure what you want to do. Given:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Last[hlistt] will resolve to AUTO_LOANS.type (your true if branch)
while init will resolve to STUDENT :: HNil (your false if branch)
the LUB (least upper bound) of these types will be Product with Serializable so that's why you see that.
If you want to check a runtime property of a member of the hlist you'll have to thread the appropriate typebounds and result types through by deriving them with the appropriate machinery. In this case that is already given by shapeless.
https://scalafiddle.io/sf/fdtn3cz/0
Is this what you wanted?
EDIT:
I also just read
I have this type which will be generated dynamically:
what do you exactly mean by "dynamically"? because unless you can specify some compile time properties, shapeless might not be the solution you're looking for.
You got very close to what I want. Do you know why I can't do:if(last(hlist).value == "student") Some(last(hlist)) else getLastOrNone(init(hlist))and adding a case forHNil. I get a type mismatch. I'm trying to traverse the HList and do a find node by value instead of by type.
– Adrian
Nov 20 at 17:40
the problem with that is that you won't know at compile time what the output type of your function is because it depends on runtime values. What is your motivation to useHList?
– Dominic Egger
Nov 20 at 17:53
I want to preserve the types ofCarandStudentin your sample code. The actual problem I'm having is given a string "student" or "car" get the correct singleton ie Student or Car. I have type classes defined on these singleton types which is why I'm trying really hard to preserve types. I'm also looking into making some mapping of "car"->Car,"student"->Student so when I'm given a text I can use it as a key to get the appropriate type
– Adrian
Nov 20 at 18:29
1
well technically I guess you could formulate a function that goes from some hlistA :: B :: C :: HNiltoA :+: B :+: C :+: Unit :+: CNiland finds the first match for some predicate poly-function or returnsUnit. But because you base this off runtime values I don't think you can do it directly. what would the returntype of that function be? so it'd go more towards a solution as Dmytro said bellow.
– Dominic Egger
Nov 20 at 18:47
Ya that's my roadblock: don't know what the type of that method would be :(
– Adrian
Nov 20 at 18:55
|
show 1 more comment
up vote
1
down vote
I am not quite sure what you want to do. Given:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Last[hlistt] will resolve to AUTO_LOANS.type (your true if branch)
while init will resolve to STUDENT :: HNil (your false if branch)
the LUB (least upper bound) of these types will be Product with Serializable so that's why you see that.
If you want to check a runtime property of a member of the hlist you'll have to thread the appropriate typebounds and result types through by deriving them with the appropriate machinery. In this case that is already given by shapeless.
https://scalafiddle.io/sf/fdtn3cz/0
Is this what you wanted?
EDIT:
I also just read
I have this type which will be generated dynamically:
what do you exactly mean by "dynamically"? because unless you can specify some compile time properties, shapeless might not be the solution you're looking for.
You got very close to what I want. Do you know why I can't do:if(last(hlist).value == "student") Some(last(hlist)) else getLastOrNone(init(hlist))and adding a case forHNil. I get a type mismatch. I'm trying to traverse the HList and do a find node by value instead of by type.
– Adrian
Nov 20 at 17:40
the problem with that is that you won't know at compile time what the output type of your function is because it depends on runtime values. What is your motivation to useHList?
– Dominic Egger
Nov 20 at 17:53
I want to preserve the types ofCarandStudentin your sample code. The actual problem I'm having is given a string "student" or "car" get the correct singleton ie Student or Car. I have type classes defined on these singleton types which is why I'm trying really hard to preserve types. I'm also looking into making some mapping of "car"->Car,"student"->Student so when I'm given a text I can use it as a key to get the appropriate type
– Adrian
Nov 20 at 18:29
1
well technically I guess you could formulate a function that goes from some hlistA :: B :: C :: HNiltoA :+: B :+: C :+: Unit :+: CNiland finds the first match for some predicate poly-function or returnsUnit. But because you base this off runtime values I don't think you can do it directly. what would the returntype of that function be? so it'd go more towards a solution as Dmytro said bellow.
– Dominic Egger
Nov 20 at 18:47
Ya that's my roadblock: don't know what the type of that method would be :(
– Adrian
Nov 20 at 18:55
|
show 1 more comment
up vote
1
down vote
up vote
1
down vote
I am not quite sure what you want to do. Given:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Last[hlistt] will resolve to AUTO_LOANS.type (your true if branch)
while init will resolve to STUDENT :: HNil (your false if branch)
the LUB (least upper bound) of these types will be Product with Serializable so that's why you see that.
If you want to check a runtime property of a member of the hlist you'll have to thread the appropriate typebounds and result types through by deriving them with the appropriate machinery. In this case that is already given by shapeless.
https://scalafiddle.io/sf/fdtn3cz/0
Is this what you wanted?
EDIT:
I also just read
I have this type which will be generated dynamically:
what do you exactly mean by "dynamically"? because unless you can specify some compile time properties, shapeless might not be the solution you're looking for.
I am not quite sure what you want to do. Given:
type hlistt = STUDENT.type :: AUTO_LOANS.type :: HNil
Last[hlistt] will resolve to AUTO_LOANS.type (your true if branch)
while init will resolve to STUDENT :: HNil (your false if branch)
the LUB (least upper bound) of these types will be Product with Serializable so that's why you see that.
If you want to check a runtime property of a member of the hlist you'll have to thread the appropriate typebounds and result types through by deriving them with the appropriate machinery. In this case that is already given by shapeless.
https://scalafiddle.io/sf/fdtn3cz/0
Is this what you wanted?
EDIT:
I also just read
I have this type which will be generated dynamically:
what do you exactly mean by "dynamically"? because unless you can specify some compile time properties, shapeless might not be the solution you're looking for.
answered Nov 20 at 9:29
Dominic Egger
64317
64317
You got very close to what I want. Do you know why I can't do:if(last(hlist).value == "student") Some(last(hlist)) else getLastOrNone(init(hlist))and adding a case forHNil. I get a type mismatch. I'm trying to traverse the HList and do a find node by value instead of by type.
– Adrian
Nov 20 at 17:40
the problem with that is that you won't know at compile time what the output type of your function is because it depends on runtime values. What is your motivation to useHList?
– Dominic Egger
Nov 20 at 17:53
I want to preserve the types ofCarandStudentin your sample code. The actual problem I'm having is given a string "student" or "car" get the correct singleton ie Student or Car. I have type classes defined on these singleton types which is why I'm trying really hard to preserve types. I'm also looking into making some mapping of "car"->Car,"student"->Student so when I'm given a text I can use it as a key to get the appropriate type
– Adrian
Nov 20 at 18:29
1
well technically I guess you could formulate a function that goes from some hlistA :: B :: C :: HNiltoA :+: B :+: C :+: Unit :+: CNiland finds the first match for some predicate poly-function or returnsUnit. But because you base this off runtime values I don't think you can do it directly. what would the returntype of that function be? so it'd go more towards a solution as Dmytro said bellow.
– Dominic Egger
Nov 20 at 18:47
Ya that's my roadblock: don't know what the type of that method would be :(
– Adrian
Nov 20 at 18:55
|
show 1 more comment
You got very close to what I want. Do you know why I can't do:if(last(hlist).value == "student") Some(last(hlist)) else getLastOrNone(init(hlist))and adding a case forHNil. I get a type mismatch. I'm trying to traverse the HList and do a find node by value instead of by type.
– Adrian
Nov 20 at 17:40
the problem with that is that you won't know at compile time what the output type of your function is because it depends on runtime values. What is your motivation to useHList?
– Dominic Egger
Nov 20 at 17:53
I want to preserve the types ofCarandStudentin your sample code. The actual problem I'm having is given a string "student" or "car" get the correct singleton ie Student or Car. I have type classes defined on these singleton types which is why I'm trying really hard to preserve types. I'm also looking into making some mapping of "car"->Car,"student"->Student so when I'm given a text I can use it as a key to get the appropriate type
– Adrian
Nov 20 at 18:29
1
well technically I guess you could formulate a function that goes from some hlistA :: B :: C :: HNiltoA :+: B :+: C :+: Unit :+: CNiland finds the first match for some predicate poly-function or returnsUnit. But because you base this off runtime values I don't think you can do it directly. what would the returntype of that function be? so it'd go more towards a solution as Dmytro said bellow.
– Dominic Egger
Nov 20 at 18:47
Ya that's my roadblock: don't know what the type of that method would be :(
– Adrian
Nov 20 at 18:55
You got very close to what I want. Do you know why I can't do:
if(last(hlist).value == "student") Some(last(hlist)) else getLastOrNone(init(hlist)) and adding a case for HNil. I get a type mismatch. I'm trying to traverse the HList and do a find node by value instead of by type.– Adrian
Nov 20 at 17:40
You got very close to what I want. Do you know why I can't do:
if(last(hlist).value == "student") Some(last(hlist)) else getLastOrNone(init(hlist)) and adding a case for HNil. I get a type mismatch. I'm trying to traverse the HList and do a find node by value instead of by type.– Adrian
Nov 20 at 17:40
the problem with that is that you won't know at compile time what the output type of your function is because it depends on runtime values. What is your motivation to use
HList?– Dominic Egger
Nov 20 at 17:53
the problem with that is that you won't know at compile time what the output type of your function is because it depends on runtime values. What is your motivation to use
HList?– Dominic Egger
Nov 20 at 17:53
I want to preserve the types of
Car and Student in your sample code. The actual problem I'm having is given a string "student" or "car" get the correct singleton ie Student or Car. I have type classes defined on these singleton types which is why I'm trying really hard to preserve types. I'm also looking into making some mapping of "car"->Car,"student"->Student so when I'm given a text I can use it as a key to get the appropriate type– Adrian
Nov 20 at 18:29
I want to preserve the types of
Car and Student in your sample code. The actual problem I'm having is given a string "student" or "car" get the correct singleton ie Student or Car. I have type classes defined on these singleton types which is why I'm trying really hard to preserve types. I'm also looking into making some mapping of "car"->Car,"student"->Student so when I'm given a text I can use it as a key to get the appropriate type– Adrian
Nov 20 at 18:29
1
1
well technically I guess you could formulate a function that goes from some hlist
A :: B :: C :: HNil to A :+: B :+: C :+: Unit :+: CNil and finds the first match for some predicate poly-function or returns Unit. But because you base this off runtime values I don't think you can do it directly. what would the returntype of that function be? so it'd go more towards a solution as Dmytro said bellow.– Dominic Egger
Nov 20 at 18:47
well technically I guess you could formulate a function that goes from some hlist
A :: B :: C :: HNil to A :+: B :+: C :+: Unit :+: CNil and finds the first match for some predicate poly-function or returns Unit. But because you base this off runtime values I don't think you can do it directly. what would the returntype of that function be? so it'd go more towards a solution as Dmytro said bellow.– Dominic Egger
Nov 20 at 18:47
Ya that's my roadblock: don't know what the type of that method would be :(
– Adrian
Nov 20 at 18:55
Ya that's my roadblock: don't know what the type of that method would be :(
– Adrian
Nov 20 at 18:55
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388226%2ffunction-that-retrieves-element-from-hlist-while-preserving-its-type%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
That's not the correct code to reproduce the result you describe. For one thing,
getLast(), as posted, is not recursive.– jwvh
Nov 20 at 9:00
@jwvh good point - I wrote this late at night (my time) and initially was thinking of a recursive fn. I did mean to wrap
init(hl)intogetLast(init(hl))– Adrian
Nov 20 at 17:47