Why a list in Scala is LinkedList internally?Why are Scala's `Lists` implemented as linked listsHow do I check if a list is empty?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonWhen to use LinkedList over ArrayList in Java?Python join: why is it string.join(list) instead of list.join(string)?How to make a flat list out of list of lists?How do I get the number of elements in a list in Python?How do I concatenate two lists in Python?How to clone or copy a list?Why not inherit from List<T>?
Adding empty element to declared container without declaring type of element
Have I saved too much for retirement so far?
Simple image editor tool to draw a simple box/rectangle in an existing image
Resetting two CD4017 counters simultaneously, only one resets
Can a Bard use an arcane focus?
word describing multiple paths to the same abstract outcome
Organic chemistry Iodoform Reaction
Can I Retrieve Email Addresses from BCC?
Who must act to prevent Brexit on March 29th?
Blender - show edges angles “direction”
How to check participants in at events?
What does the "3am" section means in manpages?
How will losing mobility of one hand affect my career as a programmer?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
Lifted its hind leg on or lifted its hind leg towards?
Visiting the UK as unmarried couple
Is there enough fresh water in the world to eradicate the drinking water crisis?
What will be the benefits of Brexit?
Can I use my Chinese passport to enter China after I acquired another citizenship?
Is infinity mathematically observable?
Meta programming: Declare a new struct on the fly
How do ultrasonic sensors differentiate between transmitted and received signals?
Should my PhD thesis be submitted under my legal name?
Indicating multiple different modes of speech (fantasy language or telepathy)
Why a list in Scala is LinkedList internally?
Why are Scala's `Lists` implemented as linked listsHow do I check if a list is empty?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonWhen to use LinkedList over ArrayList in Java?Python join: why is it string.join(list) instead of list.join(string)?How to make a flat list out of list of lists?How do I get the number of elements in a list in Python?How do I concatenate two lists in Python?How to clone or copy a list?Why not inherit from List<T>?
I am new to Scala and got to know that a list in Scala is a singly Linked List under the hood.
Here is the documentation for the same:
A class for immutable linked lists representing ordered collections of elements of type A.
This class comes with two implementing case classes scala.Nil and scala.:: that implement the abstract members isEmpty, head and tail.
This class is optimal for last-in-first-out (LIFO), stack-like access patterns. If you need another access pattern, for example, random access or FIFO, consider using a collection more suited to this than List.
Why is it like that the list is a linked list internally?
Isn't it less effective in case a random access is required?
scala list linked-list implementation
add a comment |
I am new to Scala and got to know that a list in Scala is a singly Linked List under the hood.
Here is the documentation for the same:
A class for immutable linked lists representing ordered collections of elements of type A.
This class comes with two implementing case classes scala.Nil and scala.:: that implement the abstract members isEmpty, head and tail.
This class is optimal for last-in-first-out (LIFO), stack-like access patterns. If you need another access pattern, for example, random access or FIFO, consider using a collection more suited to this than List.
Why is it like that the list is a linked list internally?
Isn't it less effective in case a random access is required?
scala list linked-list implementation
2
It is more efficient for some things, less efficient for some things. The last paragraph of your quote even tells you which. However, functional languages very often have programming patterns where linked lists work well.
– Amadan
Mar 7 at 10:05
1
Actually its not aLinkedListat all, it is aConsList. It just happens to be that thatConsLists are pretty similar toLinkedListwhen you look at the performance characteristics. There are multiple implementations ofCollectionother thanListwhich will suit your needs better.
– Sarvesh Kumar Singh
Mar 7 at 10:22
3
Possible duplicate of Why are Scala's `Lists` implemented as linked lists
– Dmytro Mitin
Mar 7 at 11:15
1
@SarveshKumarSingh: "Actually it's not an apple at all, it's a fruit. It's just happens that fruits are pretty similar to apples". Every cons list is by definition a singly linked list (though not all linked lists are cons lists - e.g. doubly-linked lists).
– Amadan
Mar 8 at 11:16
add a comment |
I am new to Scala and got to know that a list in Scala is a singly Linked List under the hood.
Here is the documentation for the same:
A class for immutable linked lists representing ordered collections of elements of type A.
This class comes with two implementing case classes scala.Nil and scala.:: that implement the abstract members isEmpty, head and tail.
This class is optimal for last-in-first-out (LIFO), stack-like access patterns. If you need another access pattern, for example, random access or FIFO, consider using a collection more suited to this than List.
Why is it like that the list is a linked list internally?
Isn't it less effective in case a random access is required?
scala list linked-list implementation
I am new to Scala and got to know that a list in Scala is a singly Linked List under the hood.
Here is the documentation for the same:
A class for immutable linked lists representing ordered collections of elements of type A.
This class comes with two implementing case classes scala.Nil and scala.:: that implement the abstract members isEmpty, head and tail.
This class is optimal for last-in-first-out (LIFO), stack-like access patterns. If you need another access pattern, for example, random access or FIFO, consider using a collection more suited to this than List.
Why is it like that the list is a linked list internally?
Isn't it less effective in case a random access is required?
scala list linked-list implementation
scala list linked-list implementation
asked Mar 7 at 9:58
KayVKayV
4,04522763
4,04522763
2
It is more efficient for some things, less efficient for some things. The last paragraph of your quote even tells you which. However, functional languages very often have programming patterns where linked lists work well.
– Amadan
Mar 7 at 10:05
1
Actually its not aLinkedListat all, it is aConsList. It just happens to be that thatConsLists are pretty similar toLinkedListwhen you look at the performance characteristics. There are multiple implementations ofCollectionother thanListwhich will suit your needs better.
– Sarvesh Kumar Singh
Mar 7 at 10:22
3
Possible duplicate of Why are Scala's `Lists` implemented as linked lists
– Dmytro Mitin
Mar 7 at 11:15
1
@SarveshKumarSingh: "Actually it's not an apple at all, it's a fruit. It's just happens that fruits are pretty similar to apples". Every cons list is by definition a singly linked list (though not all linked lists are cons lists - e.g. doubly-linked lists).
– Amadan
Mar 8 at 11:16
add a comment |
2
It is more efficient for some things, less efficient for some things. The last paragraph of your quote even tells you which. However, functional languages very often have programming patterns where linked lists work well.
– Amadan
Mar 7 at 10:05
1
Actually its not aLinkedListat all, it is aConsList. It just happens to be that thatConsLists are pretty similar toLinkedListwhen you look at the performance characteristics. There are multiple implementations ofCollectionother thanListwhich will suit your needs better.
– Sarvesh Kumar Singh
Mar 7 at 10:22
3
Possible duplicate of Why are Scala's `Lists` implemented as linked lists
– Dmytro Mitin
Mar 7 at 11:15
1
@SarveshKumarSingh: "Actually it's not an apple at all, it's a fruit. It's just happens that fruits are pretty similar to apples". Every cons list is by definition a singly linked list (though not all linked lists are cons lists - e.g. doubly-linked lists).
– Amadan
Mar 8 at 11:16
2
2
It is more efficient for some things, less efficient for some things. The last paragraph of your quote even tells you which. However, functional languages very often have programming patterns where linked lists work well.
– Amadan
Mar 7 at 10:05
It is more efficient for some things, less efficient for some things. The last paragraph of your quote even tells you which. However, functional languages very often have programming patterns where linked lists work well.
– Amadan
Mar 7 at 10:05
1
1
Actually its not a
LinkedList at all, it is a Cons List. It just happens to be that that Cons Lists are pretty similar to LinkedList when you look at the performance characteristics. There are multiple implementations of Collection other than List which will suit your needs better.– Sarvesh Kumar Singh
Mar 7 at 10:22
Actually its not a
LinkedList at all, it is a Cons List. It just happens to be that that Cons Lists are pretty similar to LinkedList when you look at the performance characteristics. There are multiple implementations of Collection other than List which will suit your needs better.– Sarvesh Kumar Singh
Mar 7 at 10:22
3
3
Possible duplicate of Why are Scala's `Lists` implemented as linked lists
– Dmytro Mitin
Mar 7 at 11:15
Possible duplicate of Why are Scala's `Lists` implemented as linked lists
– Dmytro Mitin
Mar 7 at 11:15
1
1
@SarveshKumarSingh: "Actually it's not an apple at all, it's a fruit. It's just happens that fruits are pretty similar to apples". Every cons list is by definition a singly linked list (though not all linked lists are cons lists - e.g. doubly-linked lists).
– Amadan
Mar 8 at 11:16
@SarveshKumarSingh: "Actually it's not an apple at all, it's a fruit. It's just happens that fruits are pretty similar to apples". Every cons list is by definition a singly linked list (though not all linked lists are cons lists - e.g. doubly-linked lists).
– Amadan
Mar 8 at 11:16
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f55040875%2fwhy-a-list-in-scala-is-linkedlist-internally%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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%2f55040875%2fwhy-a-list-in-scala-is-linkedlist-internally%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
2
It is more efficient for some things, less efficient for some things. The last paragraph of your quote even tells you which. However, functional languages very often have programming patterns where linked lists work well.
– Amadan
Mar 7 at 10:05
1
Actually its not a
LinkedListat all, it is aConsList. It just happens to be that thatConsLists are pretty similar toLinkedListwhen you look at the performance characteristics. There are multiple implementations ofCollectionother thanListwhich will suit your needs better.– Sarvesh Kumar Singh
Mar 7 at 10:22
3
Possible duplicate of Why are Scala's `Lists` implemented as linked lists
– Dmytro Mitin
Mar 7 at 11:15
1
@SarveshKumarSingh: "Actually it's not an apple at all, it's a fruit. It's just happens that fruits are pretty similar to apples". Every cons list is by definition a singly linked list (though not all linked lists are cons lists - e.g. doubly-linked lists).
– Amadan
Mar 8 at 11:16