Curioso que muy pocas personas se interesen por este curso.
Introducción a Scala y configuración del entorno de desarrollo
Introducción al curso y presentación de los objetivos
Scala en la historia
Instalando JVM, SBT y editores
Instalación de las herramientas
¡Hola, Mundo!
Fundamentos de Programación Funcional
Tipos de datos básicos
Inmutabilidad
Expresiones
Funciones
Colecciones: Secuencias, Conjuntos y Mapas
Tuplas y Objetos
La función de copy y el concepto de Lences
Conceptos básicos de Programación Funcional
Pattern Matching
Tail recursion
Agregación
Fundamentos teoricos
Funciones totales y parciales
Razonamiento inductivo
Razonamiento con tipos
Traits
Tipos genéricos
Tipos de datos algebraicos
Evaluación peresoza (Lazy)
Disyunciones: Option
Disyunciones: Either, try
Proyecto de Backend
Introducción e iniciación del proyecto
Modelo por Actores
Modelo de datos
Configuración de Slick
Controladores: Cómo obtener información de la base de datos
Controladores: Crear, actualizar y eliminar información de la base de datos
Computación paralela, asíncrona y concurrente
Serialización
Validación
Manejo de errores en el proyecto
Exportación del proyecto
Conclusiones
Clase final
You don't have access to this class
Keep learning! Join and start boosting your career
Tuples and objects are fundamental elements in functional and object-oriented programming that allow grouping information in an efficient way. Tuples stand out for their ability to gather different types of data in a single structure, overcoming the limitations of traditional lists that only allow homogeneous data. On the other hand, objects, especially in functional languages such as Scala, provide a more organized way of handling data by including both attributes and methods.
The main difference lies in structure and usage. While tuples are simple groupings of data, objects in functional languages present a clear distinction between classes that contain only data and those that contain only methods. This separation facilitates more modular and organized programming.
Tuples:
tuple._1
, tuple._2
, etc.Objects:
case class
to define complex structures.object.id
, object.name
.In Scala, tuples are used to store a fixed set of elements of different types. The declaration is simple and straightforward:
val myTuple = (1, "Daniel", false).
To access the elements of a tuple, we use the index of the element preceded by an underscore(_
):
myTuple._1
- Accesses the first element.myTuple._2
- Accesses the second element.myTuple._3
- Accesses the third element.case classes
?Objects in Scala, defined by case class
, provide an advanced structure for handling complex data, combining attributes and associated methods:
case class Persona(id: Int, name: String, active: Boolean)
// Creating an objectval p = Persona(1, "Daniel", true)
p.id.
tuplet
, and vice versa using unapply
.Scala allows efficient conversion between tuples and case class
objects using predefined functions:
Tuple to object conversion:
tuplet
function: converts a tuple to an object of the specified type.Object to tuple conversion:
unapply
: Extracts the values of the object and returns them as a tuple.These functions facilitate data processing and manipulation, offering flexibility in application development.
case classes
: For complex structures with the need for additional operations.Tuples and objects are powerful tools in functional programming, and understanding how to use them efficiently will allow you to write cleaner, more structured code. Take advantage of the knowledge of these structures to improve your programming skills - keep exploring and learning!
Contributions 3
Questions 1
Curioso que muy pocas personas se interesen por este curso.
¿Cómo agrupar distintos tipos de datos en uno? Una lista no funcionará como esperamos (perdemos el tipo de dato). Las tuplas son una estructura de datos flexible y potente para agrupar datos
En Scala tenemos una manera de definir clases cuyo objetivo es agrupar información. Programar de forma funcional implica separar los datos, de las operaciones sobre esos datos.
Una clase en OOP tendrá atributos y métodos juntos
En FP hay clases que contienen únicamente atributos, y habrá otras clases únicamente con operaciones
val tupla = (1, "Daniel", false)
// tupla: (Int,, String, Boolean) = 1, Daniel, false)
case class Persona(id:Int, nombre: String, activo: Boolean)
//defined class Persona
val p = Persona(1, "Daniel", true)
// p: Persona(1, "Daniel", true)
tupla._
// _1 _2 _3
tupla._1
// res2: Int = 1
tupla._2
// res2: String = Daniel
tupla._3
// res2: Boolean = false
p.id
//res4: Int = 1
p.nombre
//res4: String = Daniel
p.activo
//res4: Boolean = true
Persona.tupled(tupla)
// res12: Persona = Persona(1,Daniel,false)
Persona.unapply(p)
//res: Option[(Int,String,Boolean)] = Some((1,Daniel,true))
Estuvo genial la relaciona que hay entre tupla y objetos. Normalmente no se las relaciona, primer lenguaje que veo que si lo hacen, estuvo chévere.
Want to see more contributions, questions and answers from the community?