0Pricing
Scala for Backend Engineering & Functional Programming · Ders

Tuple Oluşturma

İlişkili değerleri birlikte paketleyin.

Tuple Oluşturma, CoddyKit'te ücretsiz bir Scala for Backend Engineering & Functional Programming dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Scala for Backend Engineering & Functional Programming öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Scala for Backend Engineering & Functional Programming kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

What Is a Tuple?

A tuple groups a fixed number of values together, even when those values have different types.

Unlike a list, where every element shares one type, a tuple can hold an Int, a String, and a Boolean all at once.

Tuples are perfect for returning or bundling a handful of related values without writing a whole class.

Creating Your First Tuple

You build a tuple by wrapping comma-separated values in parentheses.

Here we pair a name with an age. Scala figures out the types automatically.

val person = ("Alice", 30)
println(person)

Mixing Types Freely

One of the best features of tuples is mixing types in a single value.

This tuple holds a String, an Int, and a Boolean together. Each slot keeps its own type.

val record = ("Bob", 42, true)
println(record)

Tuple Types

The type of a tuple shows every element type in order.

A pair of a String and an Int has type (String, Int). You can write the type explicitly if you want to be clear.

val pair: (String, Int) = ("Cara", 25)
println(pair)

Pairs Are Common

A tuple with exactly two elements is called a pair, and pairs appear everywhere in Scala.

For example, maps are built from key-value pairs. Learning pairs first makes the rest of the language easier.

val score = ("Math", 95)
println(score)

Arrow Syntax for Pairs

For two-element tuples, Scala offers a handy arrow syntax.

Writing key -> value is exactly the same as (key, value). It reads nicely, especially when building maps.

val entry = "name" -> "Dana"
println(entry)

Larger Tuples

Tuples can hold more than two or three values.

Scala supports tuples up to 22 elements, though small tuples are easiest to read. If you need many fields, a case class is usually clearer.

val data = (1, 2, 3, 4, 5)
println(data)

Single-Element Note

There is no useful one-element tuple. Putting one value in parentheses just gives you that value back.

So (5) is simply the number 5, not a tuple. Tuples really start at two elements.

val notATuple = (5)
println(notATuple)

Tuples Are Immutable

Once you create a tuple, its values never change.

This immutability makes tuples safe to share and easy to reason about. To get a different tuple, you simply build a new one.

val a = (1, "one")
val b = (2, "two")
println(a)
println(b)

Returning Multiple Values

A common use of tuples is returning several values from a function at once.

Here a function returns both a sum and a product as a single tuple, avoiding the need for a separate class.

def stats(a: Int, b: Int) = (a + b, a * b)
println(stats(3, 4))

Nesting Tuples

Because a tuple is just a value, you can place a tuple inside another tuple.

This lets you group related sub-pairs together. Keep nesting shallow so your code stays readable.

val nested = (("x", 1), ("y", 2))
println(nested)

Quick Check

Test what you learned about creating tuples.

Recap

You learned that tuples group a fixed number of values of possibly different types inside parentheses.

Pairs can also use key -> value syntax, tuples are immutable, and they are great for returning multiple values. Next you will learn how to pull those values back out.

Sıkça Sorulan Sorular

“Tuple Oluşturma” dersi ücretsiz mi?

Evet — “Tuple Oluşturma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Scala for Backend Engineering & Functional Programming kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Scala for Backend Engineering & Functional Programming kursu toplamda 4 dersten oluşur.

“Tuple Oluşturma” dersinde ne öğreneceğim?

İlişkili değerleri birlikte paketleyin. Scala for Backend Engineering & Functional Programming ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Scala for Backend Engineering & Functional Programming öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Scala for Backend Engineering & Functional Programming, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“Tuple Oluşturma” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Scala for Backend Engineering & Functional Programming dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Scala for Backend Engineering & Functional Programming dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Tuple Oluşturma
  2. Tuple'ları Yapısökümüne Uğratma
  3. Aralıklar Oluşturma
  4. Döngülerde Aralıklar
← Scala for Backend Engineering & Functional Programming Sayfasına Dön