Drop 1st element of {#a, #b, #c} &
up vote
4
down vote
favorite
I pass the following to a function:
{#a, #b, #c} &
These are keys that are used in a list of associations.
There are instances where I want to pass only the last 2 elements, such as:
{#b, #c} &
Right now, I just rewrite it. But it seems like there should be a way to do this by getting rid of the first slot.
I looked at the full form and see that it's:
FullForm[{#a, #b, #c} &]
Function[List[Slot["a"], Slot["b"], Slot["c"]]]
I thought I could somehow get inside and drop Slot["a"]
, but can't seem to do it. I tried replacing Slot["a"]
with a blank, but I'm left with a comma at the beginning of the list. I also tried Apply
to change Function
to List
and doing it in the result. I couldn't.
Is there any way to get rid of the first element, #a
, without rewriting the expression?
expression-manipulation slot
add a comment |
up vote
4
down vote
favorite
I pass the following to a function:
{#a, #b, #c} &
These are keys that are used in a list of associations.
There are instances where I want to pass only the last 2 elements, such as:
{#b, #c} &
Right now, I just rewrite it. But it seems like there should be a way to do this by getting rid of the first slot.
I looked at the full form and see that it's:
FullForm[{#a, #b, #c} &]
Function[List[Slot["a"], Slot["b"], Slot["c"]]]
I thought I could somehow get inside and drop Slot["a"]
, but can't seem to do it. I tried replacing Slot["a"]
with a blank, but I'm left with a comma at the beginning of the list. I also tried Apply
to change Function
to List
and doing it in the result. I couldn't.
Is there any way to get rid of the first element, #a
, without rewriting the expression?
expression-manipulation slot
Instead of a blank you could replaceSlot["a"]->Nothing
. You'll get thisNothing
in the resulting function object, but once the function is applied,Nothing
will collapse.
– Ruslan
Nov 21 at 6:51
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I pass the following to a function:
{#a, #b, #c} &
These are keys that are used in a list of associations.
There are instances where I want to pass only the last 2 elements, such as:
{#b, #c} &
Right now, I just rewrite it. But it seems like there should be a way to do this by getting rid of the first slot.
I looked at the full form and see that it's:
FullForm[{#a, #b, #c} &]
Function[List[Slot["a"], Slot["b"], Slot["c"]]]
I thought I could somehow get inside and drop Slot["a"]
, but can't seem to do it. I tried replacing Slot["a"]
with a blank, but I'm left with a comma at the beginning of the list. I also tried Apply
to change Function
to List
and doing it in the result. I couldn't.
Is there any way to get rid of the first element, #a
, without rewriting the expression?
expression-manipulation slot
I pass the following to a function:
{#a, #b, #c} &
These are keys that are used in a list of associations.
There are instances where I want to pass only the last 2 elements, such as:
{#b, #c} &
Right now, I just rewrite it. But it seems like there should be a way to do this by getting rid of the first slot.
I looked at the full form and see that it's:
FullForm[{#a, #b, #c} &]
Function[List[Slot["a"], Slot["b"], Slot["c"]]]
I thought I could somehow get inside and drop Slot["a"]
, but can't seem to do it. I tried replacing Slot["a"]
with a blank, but I'm left with a comma at the beginning of the list. I also tried Apply
to change Function
to List
and doing it in the result. I couldn't.
Is there any way to get rid of the first element, #a
, without rewriting the expression?
expression-manipulation slot
expression-manipulation slot
edited Nov 20 at 21:49
Kuba♦
103k12200511
103k12200511
asked Nov 20 at 21:07
Mitchell Kaplan
1,6421026
1,6421026
Instead of a blank you could replaceSlot["a"]->Nothing
. You'll get thisNothing
in the resulting function object, but once the function is applied,Nothing
will collapse.
– Ruslan
Nov 21 at 6:51
add a comment |
Instead of a blank you could replaceSlot["a"]->Nothing
. You'll get thisNothing
in the resulting function object, but once the function is applied,Nothing
will collapse.
– Ruslan
Nov 21 at 6:51
Instead of a blank you could replace
Slot["a"]->Nothing
. You'll get this Nothing
in the resulting function object, but once the function is applied, Nothing
will collapse.– Ruslan
Nov 21 at 6:51
Instead of a blank you could replace
Slot["a"]->Nothing
. You'll get this Nothing
in the resulting function object, but once the function is applied, Nothing
will collapse.– Ruslan
Nov 21 at 6:51
add a comment |
2 Answers
2
active
oldest
votes
up vote
7
down vote
accepted
You could pass it to Delete
:
Delete[#, {1, 1}] &[{#a, #b, #c} &]
{#b, #c} &
add a comment |
up vote
5
down vote
foo = {#a, #b, #c} &;
foo[[{1}, 2 ;;]]
{#b, #c} &
or, but only because we know there won't be any side effects:
Evaluate /@ Rest /@ foo
{#b, #c} &
or
foo /. {_Slot, rest__Slot} :> {rest}
At the end consider using an operator form of a KeyDrop
bar = KeyTake[{"a", "b", "c"}];
(Rest /@ bar)@<|"a" -> 1, "b" -> 1, "c" -> 1|>
<|"b" -> 1, "c" -> 1|>
I accepted Coolwater's answer because it solved my problem simply. I appreciate the extra insight that your answer provided. Actually, I'll have to spend more time to really understand it though.
– Mitchell Kaplan
Nov 20 at 21:51
@MitchellKaplan sure, btw, can you give a little insigth into how do you use it? Because it feels like a XY problem, maybe there is a better way anyway.
– Kuba♦
Nov 20 at 21:55
I use a lot of lists of associations and very often I have to sum things by one or more keys. Why I asked this question: I work in reinsurance. My list has, among other things: treaty, effective date, line of business, IBNR. I'm estimating IBNR by all 3, but it has to balance to the total IBNR for effective/line. I need to sum both by all 3, but also by only effective/line. I call a function that does this, and I want to adjust the keys I'm using to eliminate treaty when I'm summing over just effective/line. Left some detail out to fit answer into comment.
– Mitchell Kaplan
Nov 21 at 16:51
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
You could pass it to Delete
:
Delete[#, {1, 1}] &[{#a, #b, #c} &]
{#b, #c} &
add a comment |
up vote
7
down vote
accepted
You could pass it to Delete
:
Delete[#, {1, 1}] &[{#a, #b, #c} &]
{#b, #c} &
add a comment |
up vote
7
down vote
accepted
up vote
7
down vote
accepted
You could pass it to Delete
:
Delete[#, {1, 1}] &[{#a, #b, #c} &]
{#b, #c} &
You could pass it to Delete
:
Delete[#, {1, 1}] &[{#a, #b, #c} &]
{#b, #c} &
answered Nov 20 at 21:09
Coolwater
14.4k32452
14.4k32452
add a comment |
add a comment |
up vote
5
down vote
foo = {#a, #b, #c} &;
foo[[{1}, 2 ;;]]
{#b, #c} &
or, but only because we know there won't be any side effects:
Evaluate /@ Rest /@ foo
{#b, #c} &
or
foo /. {_Slot, rest__Slot} :> {rest}
At the end consider using an operator form of a KeyDrop
bar = KeyTake[{"a", "b", "c"}];
(Rest /@ bar)@<|"a" -> 1, "b" -> 1, "c" -> 1|>
<|"b" -> 1, "c" -> 1|>
I accepted Coolwater's answer because it solved my problem simply. I appreciate the extra insight that your answer provided. Actually, I'll have to spend more time to really understand it though.
– Mitchell Kaplan
Nov 20 at 21:51
@MitchellKaplan sure, btw, can you give a little insigth into how do you use it? Because it feels like a XY problem, maybe there is a better way anyway.
– Kuba♦
Nov 20 at 21:55
I use a lot of lists of associations and very often I have to sum things by one or more keys. Why I asked this question: I work in reinsurance. My list has, among other things: treaty, effective date, line of business, IBNR. I'm estimating IBNR by all 3, but it has to balance to the total IBNR for effective/line. I need to sum both by all 3, but also by only effective/line. I call a function that does this, and I want to adjust the keys I'm using to eliminate treaty when I'm summing over just effective/line. Left some detail out to fit answer into comment.
– Mitchell Kaplan
Nov 21 at 16:51
add a comment |
up vote
5
down vote
foo = {#a, #b, #c} &;
foo[[{1}, 2 ;;]]
{#b, #c} &
or, but only because we know there won't be any side effects:
Evaluate /@ Rest /@ foo
{#b, #c} &
or
foo /. {_Slot, rest__Slot} :> {rest}
At the end consider using an operator form of a KeyDrop
bar = KeyTake[{"a", "b", "c"}];
(Rest /@ bar)@<|"a" -> 1, "b" -> 1, "c" -> 1|>
<|"b" -> 1, "c" -> 1|>
I accepted Coolwater's answer because it solved my problem simply. I appreciate the extra insight that your answer provided. Actually, I'll have to spend more time to really understand it though.
– Mitchell Kaplan
Nov 20 at 21:51
@MitchellKaplan sure, btw, can you give a little insigth into how do you use it? Because it feels like a XY problem, maybe there is a better way anyway.
– Kuba♦
Nov 20 at 21:55
I use a lot of lists of associations and very often I have to sum things by one or more keys. Why I asked this question: I work in reinsurance. My list has, among other things: treaty, effective date, line of business, IBNR. I'm estimating IBNR by all 3, but it has to balance to the total IBNR for effective/line. I need to sum both by all 3, but also by only effective/line. I call a function that does this, and I want to adjust the keys I'm using to eliminate treaty when I'm summing over just effective/line. Left some detail out to fit answer into comment.
– Mitchell Kaplan
Nov 21 at 16:51
add a comment |
up vote
5
down vote
up vote
5
down vote
foo = {#a, #b, #c} &;
foo[[{1}, 2 ;;]]
{#b, #c} &
or, but only because we know there won't be any side effects:
Evaluate /@ Rest /@ foo
{#b, #c} &
or
foo /. {_Slot, rest__Slot} :> {rest}
At the end consider using an operator form of a KeyDrop
bar = KeyTake[{"a", "b", "c"}];
(Rest /@ bar)@<|"a" -> 1, "b" -> 1, "c" -> 1|>
<|"b" -> 1, "c" -> 1|>
foo = {#a, #b, #c} &;
foo[[{1}, 2 ;;]]
{#b, #c} &
or, but only because we know there won't be any side effects:
Evaluate /@ Rest /@ foo
{#b, #c} &
or
foo /. {_Slot, rest__Slot} :> {rest}
At the end consider using an operator form of a KeyDrop
bar = KeyTake[{"a", "b", "c"}];
(Rest /@ bar)@<|"a" -> 1, "b" -> 1, "c" -> 1|>
<|"b" -> 1, "c" -> 1|>
answered Nov 20 at 21:48
Kuba♦
103k12200511
103k12200511
I accepted Coolwater's answer because it solved my problem simply. I appreciate the extra insight that your answer provided. Actually, I'll have to spend more time to really understand it though.
– Mitchell Kaplan
Nov 20 at 21:51
@MitchellKaplan sure, btw, can you give a little insigth into how do you use it? Because it feels like a XY problem, maybe there is a better way anyway.
– Kuba♦
Nov 20 at 21:55
I use a lot of lists of associations and very often I have to sum things by one or more keys. Why I asked this question: I work in reinsurance. My list has, among other things: treaty, effective date, line of business, IBNR. I'm estimating IBNR by all 3, but it has to balance to the total IBNR for effective/line. I need to sum both by all 3, but also by only effective/line. I call a function that does this, and I want to adjust the keys I'm using to eliminate treaty when I'm summing over just effective/line. Left some detail out to fit answer into comment.
– Mitchell Kaplan
Nov 21 at 16:51
add a comment |
I accepted Coolwater's answer because it solved my problem simply. I appreciate the extra insight that your answer provided. Actually, I'll have to spend more time to really understand it though.
– Mitchell Kaplan
Nov 20 at 21:51
@MitchellKaplan sure, btw, can you give a little insigth into how do you use it? Because it feels like a XY problem, maybe there is a better way anyway.
– Kuba♦
Nov 20 at 21:55
I use a lot of lists of associations and very often I have to sum things by one or more keys. Why I asked this question: I work in reinsurance. My list has, among other things: treaty, effective date, line of business, IBNR. I'm estimating IBNR by all 3, but it has to balance to the total IBNR for effective/line. I need to sum both by all 3, but also by only effective/line. I call a function that does this, and I want to adjust the keys I'm using to eliminate treaty when I'm summing over just effective/line. Left some detail out to fit answer into comment.
– Mitchell Kaplan
Nov 21 at 16:51
I accepted Coolwater's answer because it solved my problem simply. I appreciate the extra insight that your answer provided. Actually, I'll have to spend more time to really understand it though.
– Mitchell Kaplan
Nov 20 at 21:51
I accepted Coolwater's answer because it solved my problem simply. I appreciate the extra insight that your answer provided. Actually, I'll have to spend more time to really understand it though.
– Mitchell Kaplan
Nov 20 at 21:51
@MitchellKaplan sure, btw, can you give a little insigth into how do you use it? Because it feels like a XY problem, maybe there is a better way anyway.
– Kuba♦
Nov 20 at 21:55
@MitchellKaplan sure, btw, can you give a little insigth into how do you use it? Because it feels like a XY problem, maybe there is a better way anyway.
– Kuba♦
Nov 20 at 21:55
I use a lot of lists of associations and very often I have to sum things by one or more keys. Why I asked this question: I work in reinsurance. My list has, among other things: treaty, effective date, line of business, IBNR. I'm estimating IBNR by all 3, but it has to balance to the total IBNR for effective/line. I need to sum both by all 3, but also by only effective/line. I call a function that does this, and I want to adjust the keys I'm using to eliminate treaty when I'm summing over just effective/line. Left some detail out to fit answer into comment.
– Mitchell Kaplan
Nov 21 at 16:51
I use a lot of lists of associations and very often I have to sum things by one or more keys. Why I asked this question: I work in reinsurance. My list has, among other things: treaty, effective date, line of business, IBNR. I'm estimating IBNR by all 3, but it has to balance to the total IBNR for effective/line. I need to sum both by all 3, but also by only effective/line. I call a function that does this, and I want to adjust the keys I'm using to eliminate treaty when I'm summing over just effective/line. Left some detail out to fit answer into comment.
– Mitchell Kaplan
Nov 21 at 16:51
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- 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.
Use MathJax to format equations. MathJax reference.
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%2fmathematica.stackexchange.com%2fquestions%2f186391%2fdrop-1st-element-of-a-b-c%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
Instead of a blank you could replace
Slot["a"]->Nothing
. You'll get thisNothing
in the resulting function object, but once the function is applied,Nothing
will collapse.– Ruslan
Nov 21 at 6:51