Best of Functional ProgrammingJuly 2024

  1. 1
    Article
    Avatar of communityCommunity Picks·2y

    Tail Call Optimization ♻️and Recursion🔁 in JavaScript

    Recursion is a technique where a function calls itself to solve problems but can lead to high memory usage and stack overflow. Tail call optimization (TCO) addresses this by reusing stack frames for the subsequent calls when the recursive call is in the tail position. JavaScript provides partial support for TCO, with ECMAScript 6 introducing proper tail calls (PTC). Techniques like iteration, trampolining, and memoization further help optimize recursive functions. Challenges include handling deep recursion and asynchronous operations. Functional programming libraries such as Ramda offer TCO-optimized functions.

  2. 2
    Article
    Avatar of codemazeCode Maze·2y

    Local Functions vs Lambda Expressions in C#

    Local functions and lambda expressions in C# serve different purposes and have distinct performance characteristics. Local functions are methods nested within other methods and excel in performance since they can avoid heap allocation and use struct instead of class captures. Lambda expressions, while concise and useful for passing as delegates, generally require heap allocation and object instantiation. Local functions can be generic, recursive, and used as iterators, whereas lambda expressions struggle with these features. Thus, local functions are often more versatile and performant, especially when not using APIs that demand delegates.

  3. 3
    Article
    Avatar of pandProAndroidDev·2y

    Stop throwing exceptions!

    In Kotlin, it's recommended to avoid throwing exceptions and instead handle error scenarios using try/catch expressions, result objects, and functional programming paradigms. The default usage of try/catch is criticized for reducing readability and maintainability. The post suggests Kotlin's built-in Result class for better error handling, providing examples of how to wrap operations in Result objects and handle errors more effectively. This approach promotes cleaner, more testable code without relying on exceptions.

  4. 4
    Article
    Avatar of inside_javaInside Java·2y

    Converting Data Sources to Streams

    Learn how to transform imperative-style loops into functional-style streams in Java. This guide walks through converting a file-reading task using BufferedReader into a streamlined process using the Streams API. Key functions include filter() and map(), which simplify data manipulation by treating the content as streams.

  5. 5
    Article
    Avatar of elixirstatusElixirStatus·2y

    Learning Elixir as a frontend developer

    A frontend developer shares their journey of learning Elixir and Phoenix to expand their backend skills. The post highlights the initial learning curve, challenges encountered, and the satisfaction gained from mastering new concepts. It discusses both the strengths and weaknesses of Elixir, along with the overall positive experience, while emphasizing the importance of stepping out of one's comfort zone to grow professionally.

  6. 6
    Article
    Avatar of erikarowErika Rowland·2y

    Using use in Gleam

    Gleam's `use` expression simplifies handling callback functions, error management, and context management. Introduced in version 0.25, `use` replaces the need for extensive nested callbacks, making code more readable, especially when dealing with functions like `result.map` and `result.try` for error handling. It serves as syntactic sugar for creating cleaner and more maintainable code, similar to Rust's `?` operator.

  7. 7
    Article
    Avatar of foojayioFoojay.io·2y

    Java: Demystifying The Stream API

    The post explains the Java Stream API, which is a collection of functions that enable a more declarative and functional way of processing data collections. Key operations such as map, filter, and reduce are discussed, with examples of their use. The post also covers intermediate and terminal operations, parallel processing with streams, and performance considerations compared to traditional for loops. Tips for error handling and best practices for using streams are provided.

  8. 8
    Article
    Avatar of lobstersLobsters·2y

    "Functional programming languages should be so much better at mutation than they are"

    Functional programming languages often struggle with mutation, leading to unnecessary overhead and complexity. The post explores various approaches to incorporate mutation in functional languages, such as allowing mutable data structures, locally limited mutations, linearity, and functional but in-place data structures. Each approach comes with its own set of challenges, and the search for a robust solution continues.

  9. 9
    Article
    Avatar of hnHacker News·2y

    tekknolagi/scrapscript: A functional, content-addressable programming language.

    Scrapscript is a functional, content-addressable programming language. It supports python3.8+ and provides various methods for interaction including file, string literal, and REPL modes. Developers can run scrapscript using Python, Cosmopolitan, or Docker. Compilation options are also available, generating C output or executables.

  10. 10
    Article
    Avatar of baeldungBaeldung·2y

    How to Sort Map Value List by Element Field Using Java Streams

    Learn how to use Java's Stream API to sort a list of Employee objects stored within a Map, comparing it to the traditional List#sort(Comparator) method. The tutorial walks through reading employee data from a CSV file, storing it in a nested Map structure, and demonstrates sorting by salary and name using both methods. The Stream API offers improved readability, flexibility, and adherence to functional programming principles such as immutability and statelessness.

  11. 11
    Video
    Avatar of communityCommunity Picks·2y

    Functional Design Patterns - Scott Wlaschin

  12. 12
    Article
    Avatar of appsignalAppSignal·2y

    Enhancing Your Elixir Codebase with Gleam

    Enhance your Elixir codebase with the type safety of Gleam, a statically typed language for the BEAM platform. By integrating Gleam with your Elixir projects, you can ensure robust and reliable business logic while maintaining the dynamic flexibility of Elixir. This post provides a detailed guide to setting up a Phoenix project, integrating Gleam, writing and testing business logic, and managing features like waitlists for student enrollment in a university application.

  13. 13
    Article
    Avatar of elixirstatusElixirStatus·2y

    Introduction to Elixir: Key Reasons to Choose This Dynamic Language

    Elixir is a high-level, general-purpose programming language built on the Erlang VM (BEAM), designed for concurrency, fault tolerance, and developer productivity. Created by José Valim, it combines Erlang's robustness with Ruby's syntax to improve developer satisfaction. Key features include metaprogramming, efficient resource usage, and strong concurrency models, making it ideal for backend systems, real-time apps, machine learning, and more. While it has a steep learning curve and a smaller ecosystem, Elixir excels in scalability and fault tolerance, potentially offering significant benefits for complex projects.