liveBook · Manning

First element

A first operation retrieves the initial element of a sequence or collection, optionally subject to a predicate, and indicates when no matching element exists.

How 2 Manning books explain it

Clojure: The Essential Reference

first is a Clojure function that returns the first element of a sequenceable collection or nil when none is available.

How it is used
Selects a collection’s head during sequential processing, including transformations that extract one field from each item.
How deep it goes
Defines the one-argument contract and nil edge cases, then illustrates collection-dependent ordering and access alternatives without implementing the function.
Examples
Uses a list lookup, area-code extraction from phone numbers, and map and set lookups to show differing sequential views.
What you can do after
Apply it via Clojure’s standard library to retrieve a sequence head or extract leading fields with map.

Read how Clojure: The Essential Reference explains first element →

The Well-Grounded Rubyist, Fourth Edition

first is an Enumerable method that returns the first element or a specified number of initial elements from an enumerable object.

How it is used
Retrieves the beginning of arrays, ranges, hashes, and other Enumerable objects during collection querying.
How deep it goes
Explains return shapes, hash iteration, infinite enumerables, and lazy evaluation, but does not exhaustively catalog Enumerable methods.
Examples
Uses arrays, ranges, hashes, an infinite die iterator, and multiples of three selected from an infinite range.
What you can do after
Apply it via Ruby's Enumerable API to obtain one item or a finite initial slice from an iterable, including lazy infinite sequences.

Read how The Well-Grounded Rubyist, Fourth Edition explains first element →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.