Introducción a la programación Funcional

1

¿Qué es la Programación Funcional?

Entendiendo las partes de la programación funcional

2

¿Qué es una función en Java?

3

Funciones como ciudadanos de primera clase

4

Funciones puras

5

Entendiendo los efectos secundarios

6

Funciones de orden mayor

7

Funciones lambda

8

Inmutabilidad

Functional Programming en Java

9

Repositorio del curso

10

Configuración del entorno de trabajo

11

Revisando el paquete java.util.function: Function

12

Revisando el paquete java.util.function: Predicate

13

Revisando el paquete java.util.function: Consumer y Supplier

14

Revisando el paquete java.util.function: Operators y BiFunction

15

Entendiendo dos jugadores clave: SAM y FunctionalInterface

16

Operador de Referencia

17

Analizando la inferencia de tipos

18

Comprendiendo la sintaxis de las funciones lambda

19

Usando metodos default en nuestras interfaces

20

Dándole nombre a un viejo amigo: Chaining

21

Entendiendo la composición de funciones

Optional y Streams: Datos mas interesantes

22

La clase Optional

23

Entendiendo los Streams

24

¿Qué son los Stream listeners?

25

Operaciones y Collectors

26

Streams de tipo específico y Paralelismo

27

Operaciones Terminales

28

Operaciones Intermedias

29

Collectors

Todo junto: Proyecto Job-search

30

job-search: Un proyecto para encontrar trabajo

31

Vista rápida a un proyecto de Gradle

32

Revisando las opciones para nuestro CLI

33

Librerías adicionales para nuestro proyecto

34

Entendiendo la API de jobs

35

Diseñando las Funciones Constructoras de nuestro Proyecto

36

Agregando validaciones de datos

37

Diseñando las funciones de transformacion de datos

38

Creando flujos extras de transformación de Datos

Conclusiones

39

Un repaso a lo aprendido

You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

2 Días
15 Hrs
24 Min
22 Seg

Analizando la inferencia de tipos

17/39
Resources

What is type inference in programming?

Modern programming has evolved in a way that facilitates the developer's work, one of these features is type inference. This concept allows the compiler to automatically deduce the type of data being used within a function or expression, without the need for the programmer to specify it explicitly. This not only makes the code cleaner and more readable, but also reduces the risk of errors.

How does type inference work?

To understand how it works, let's take as an example a programming language that uses type inference during compilation. The process starts when we define a function. Suppose we make a function that receives an Integer and returns a String. This function, which we will call converter, takes the integer value, multiplies it by two and then converts it to a String.

public String converter(Integer value) { return Integer.toString(value * 2);}

In this case, although we do not specify that the parameter is an integer within the method, the compiler is able to determine that value is an integer because of the context in which it is used and how it is manipulated.

Why is type inference important?

Type inference has multiple benefits in software development:

  • Code Simplification: By not having to explicitly declare types, code becomes simpler and less verbose.
  • Reduced Type Error: During compilation, the system can verify that the data matches the expected types, minimizing errors.
  • Facilitates Refactoring: With type inference, modifying and refactoring the code becomes much simpler and faster, since the compiler itself takes care of much of the validation work.

Practical example: list of students

To deepen the concept, let's consider an example used in object-oriented programming. Let's imagine that we create a list of students in which we directly store references to other methods that generate student names.

public List<String> getName() { return Arrays.asList("Juan", "Paco", "Luiza");}

During list processing, we can use reference-based methods, which will act on the list elements without requiring the types to be explicitly specified. This capability is based on type inference that validates during compilation that the methods receive and return the correct types.

What are the limitations?

Although type inference offers great benefits, it also has its limits. In some situations, the lack of explicit specification can lead to confusion about what type of data is being manipulated, making it difficult to maintain in large projects. Therefore, it is important to find a balance between using inference and clear type specification to keep the code readable and manageable.

In short, type inference is a powerful tool that, when used correctly, significantly optimizes software development, making the coding process more efficient and less error-prone, so don't hesitate to explore and apply this concept in your next projects!

Contributions 17

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

Esto debería haber sido explicado antes. Hizo como 20 ejemplos en clases anteriores dándolo por entendido poniendo simplemente <T,V,R> y tipeando a toda velocidad sin detenerse, y para los que venimos de practicar solo con POO es imposible verlo.

Que desorden este curso. Creo que por el afán de explicar los conceptos en el tiempo limite, no estructuraron bien este curso y hace un poco difícil asimilar todo lo que se explica aquí. Mal, no me ha gustado este curso!

Me encanta poder entender por fin el operador de referencia ::
Pero me parece horroroso, hace el código muy poco legible…

¿Si abusamos de la inferencia de tipos, podría afectar el rendimiento y la legibilidad del código?

La inferencia del tipo, java lo hace es que en tiempo de ejecucion valida el valor que pasas sea del tipo que se requiere

La inferencia de tipos es un algo que nos ayuda a escribir menos código, ¿Esto hace que el lenguaje pierda su propiedad de que es fuertemente tipado?
Veo que igual los parámetros que entraran tienen que tener su tipo bien definido.

Para los que dicen que esto no se había explicado antes, si se hizo, en el curso de Introducción a Java SE se hablo sobre la inferencia, solo que aquí lo estamos haciendo con funciones.

import java.util.function.*;
import java.util.List;

public class Inferencia {
	
	public static void main(String[] args) {
		
		Function<Integer, String> funcionConvertidora = 
				x -> "Al doble :" + (x * 2);
	
	    List<String> alumnos = NombresUtils.getList("Ulises","Dhamar","Jareny");
	    alumnos.forEach((String name) -> System.out.println(name));
	    alumnos.forEach((name) -> System.out.println(name));
	    alumnos.forEach(System.out::println);
		
	}

}

Excelente clase

Excelente, muy buena explicacion

Algo similar a lo que hace kotlin, solo que kotlin infiere tipos desde el momento que declaras una variable.

Excelente 😃

Excelente info

Estupenda utilidad de esta forma Java determinara los tipos de datos al hacer la compilación y nos ahorra algunas líneas de código, además de asegurarnos que se cumpla con el proceso de la función que se estableció.

Es interesante, muchas gracias por la explicacion. Aunque si concuerdo un poco que esto se pudo explciar antes, pero de igual forma se explico en un momento oportuno.

Es la nueva forma que Java nos permite escribir menos código ya que él se encargara de saber qué tipo de dato debe manejar, tiene sus pro y contras como todo pero creo que tiene más pro ya que al hacerlo en tiempo de compilación no tendríamos preocupación del proyecto en producción, igual Java nos alertaría si encontrase algún problema.