Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 943161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:23:31+00:00 2026-05-15T22:23:31+00:00

So, Erlang is a real joy to work with, but there’s one problem I

  • 0

So, Erlang is a real joy to work with, but there’s one problem I run into occasionally, that I’m wondering if there is a nicer way to solve. Often, I find myself needing to split several items from a list. The syntax for splitting a list into a Head and Tail is straight forward enough, but what about when there are multiple items.

1> List = [1,2,3,4,5].
[1,2,3,4,5]
2> [Head | Tail] = List.
[1,2,3,4,5]
3> Head.
1
4> Tail.
[2,3,4,5]

Is there a nicer way to get, say, the first two elements of a list other than splitting twice inline?

1> List = [1,2,3,4,5].
[1,2,3,4,5]
2> [Head1 | [Head2 | Tail]] = List.
[1,2,3,4,5]
3> Head1.
1
4> Head2.
2
5> Tail.
[3,4,5]

I know that this can also be simplified by writing functions that recursively split subsequent heads from a list, but I’m wondering if there is a simpler inline way to do it (or if in fact, the recursive subsequent split functions are the best practices way to accomplish this task)? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:23:32+00:00Added an answer on May 15, 2026 at 10:23 pm
    [X1, X2 | Tail] = List.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the Erlang crypto library, there is no aes_cfb_ivec function. Does it mean that
There are certain common library functions in erlang that are much slower than their
This is an erlang problem, it seems. I have this code to test the
I have a process in erlang that is supposed to do something immediately after
Assume that we have N erlang nodes, running same application. I want to share
I'd like to get a real XSLT processor working with erlang. Which would be
What are the best examples of real life protocols that tunnel through HTTP? XMPP/Jabber?
There are many datastores written in Erlang, for example Riak, Dynomite, CouchDb, Scalaris, have
Can I format an Erlang binary so that each byte is written in hex?
Erlang with mnesia/dets is famous for it slow startup times after a crash. Basically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.