# forEach

Published articles for forEach.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## JavaScript Modulo (%): Remainder Operator Explained

DevFeed: [JavaScript Modulo (%): Remainder Operator Explained](<https://devfeed.tech/articles/javascript-modulo-remainder-operator-explained-116067.md>)

Original publisher: [Read original article](<https://markodenic.com/javascript-modulo/>)

Author: Marko

Published: 2026-11-03T09:00:00Z

Content type: article

Language: en

Sources: [Marko Denic Blog](<https://devfeed.tech/sources/marko-denic-blog.md>)

Topics: [JavaScript](<https://devfeed.tech/topics/javascript.md>)

Tags: [array](<https://devfeed.tech/tags/array.md>), [bigint](<https://devfeed.tech/tags/bigint.md>), [calc](<https://devfeed.tech/tags/calc.md>), [clamp](<https://devfeed.tech/tags/clamp.md>), [css](<https://devfeed.tech/tags/css.md>), [dividend](<https://devfeed.tech/tags/dividend.md>), [floating-point](<https://devfeed.tech/tags/floating-point.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [function](<https://devfeed.tech/tags/function.md>), [index](<https://devfeed.tech/tags/index.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [min](<https://devfeed.tech/tags/min.md>), [minutes](<https://devfeed.tech/tags/minutes.md>), [numbers](<https://devfeed.tech/tags/numbers.md>), [operator](<https://devfeed.tech/tags/operator.md>), [python](<https://devfeed.tech/tags/python.md>), [sign](<https://devfeed.tech/tags/sign.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>)

### AI overview

JavaScript's `%` operator returns a remainder, whose sign follows the left operand; it is therefore not true modulo for negative values. The excerpt shows uses for divisibility and even/odd checks, periodic actions, wrapping array indexes, and splitting seconds into minutes and seconds. For a nonnegative modulo result, it gives `((n % m) + m) % m`. It also notes that decimal remainders can be imprecise because of floating-point representation, BigInt operands must both be BigInts, and `% 0` yields `NaN`.

### Source excerpt

How the % operator works in JavaScript: remainders, even and odd checks, why negative numbers give negative results, a true modulo function, and practical uses like wrapping indexes and time formatting.

## WebKit Features for Safari 27.1

DevFeed: [WebKit Features for Safari 27.1](<https://devfeed.tech/articles/webkit-features-for-safari-27-1-98566.md>)

Original publisher: [Read original article](<https://webkit.org/blog/18486/webkit-features-for-safari-27-1/>)

Author: Jen Simmons

Published: 2026-10-23T17:00:59Z

Content type: release

Language: en

Sources: [WebKit](<https://devfeed.tech/sources/webkit.md>)

Topics: [Responsive Design](<https://devfeed.tech/topics/responsive-design.md>), [WebKit](<https://devfeed.tech/topics/webkit.md>), [Media Queries](<https://devfeed.tech/topics/media-queries.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [array](<https://devfeed.tech/tags/array.md>), [bluesky](<https://devfeed.tech/tags/bluesky.md>), [continuous](<https://devfeed.tech/tags/continuous.md>), [css](<https://devfeed.tech/tags/css.md>), [css-grid](<https://devfeed.tech/tags/css-grid.md>), [developer-preview](<https://devfeed.tech/tags/developer-preview.md>), [duo](<https://devfeed.tech/tags/duo.md>), [environment-variables](<https://devfeed.tech/tags/environment-variables.md>), [event](<https://devfeed.tech/tags/event.md>), [feature-detection](<https://devfeed.tech/tags/feature-detection.md>), [feature-flags](<https://devfeed.tech/tags/feature-flags.md>), [flexbox](<https://devfeed.tech/tags/flexbox.md>), [folding](<https://devfeed.tech/tags/folding.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [iphone](<https://devfeed.tech/tags/iphone.md>), [iphone-duo](<https://devfeed.tech/tags/iphone-duo.md>), [news](<https://devfeed.tech/tags/news.md>), [safari](<https://devfeed.tech/tags/safari.md>), [webkit](<https://devfeed.tech/tags/webkit.md>)

### AI overview

Safari 27.1 keeps the same WebKit engine and web technologies as other iPhones. For users, its notable change is displaying web PDFs as facing pages when iPhone Duo is partly folded, returning to one page when flat or closed. Developers can preview the Device Posture and Viewport Segments APIs behind feature flags: posture is exposed through CSS and JavaScript, while segment media queries, environment variables, and JavaScript rectangles describe areas around the fold. The article says responsive layouts and feature detection support the device's range of viewport sizes, and an iPhone Duo simulator is available in Xcode 27.1 or later. Web content currently does not extend behind the outer display's side controls; Apple is exploring ways to enable that, noting that viewport-fit="cover" depends on correctly insetting content from system controls.

### Source excerpt

Today iPhone Duo arrives, and with it, Safari 27.1.

## Babel in Khan Academy's i18n Toolchain

DevFeed: [Babel in Khan Academy's i18n Toolchain](<https://devfeed.tech/articles/babel-in-khan-academy-s-i18n-toolchain-27381.md>)

Original publisher: [Read original article](<http://engineering.khanacademy.org/posts/i18n-babel-plugin.htm>)

Author: Khan Academy

Published: 2015-06-22T22:00:00Z

Content type: article

Language: en

Sources: [Khan Academy](<https://devfeed.tech/sources/khan-academy.md>)

Topics: [Babel](<https://devfeed.tech/topics/babel.md>), [Internationalization (i18n)](<https://devfeed.tech/topics/i18n.md>), [ECMAScript](<https://devfeed.tech/topics/ecmascript.md>), [React](<https://devfeed.tech/topics/react.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [argument](<https://devfeed.tech/tags/argument.md>), [arguments](<https://devfeed.tech/tags/arguments.md>), [ast](<https://devfeed.tech/tags/ast.md>), [babel](<https://devfeed.tech/tags/babel.md>), [build-system](<https://devfeed.tech/tags/build-system.md>), [callback](<https://devfeed.tech/tags/callback.md>), [class](<https://devfeed.tech/tags/class.md>), [classes](<https://devfeed.tech/tags/classes.md>), [destructuring](<https://devfeed.tech/tags/destructuring.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [es6](<https://devfeed.tech/tags/es6.md>), [eslint](<https://devfeed.tech/tags/eslint.md>), [exports](<https://devfeed.tech/tags/exports.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [frontend](<https://devfeed.tech/tags/frontend.md>), [function](<https://devfeed.tech/tags/function.md>), [functions](<https://devfeed.tech/tags/functions.md>), [i18n](<https://devfeed.tech/tags/i18n.md>), [jsx](<https://devfeed.tech/tags/jsx.md>), [news](<https://devfeed.tech/tags/news.md>), [web-frontend](<https://devfeed.tech/tags/web-frontend.md>)

### AI overview

Khan Academy's Babel migration preserved its custom i18n workflow by adding a Babel plugin that turns `<$_>` and `<$i18nDoNotTranslate>` JSX tags into function calls. Matching jstransform required retaining generated line numbers and exact whitespace in translation strings; the team compared Gettext `.pot` files from both build paths and used fixtures to isolate whitespace differences. Migration testing also caught two transformer issues: class output still contained `let` until `es6.blockScoping` was added to the whitelist, and Babel's function-name transformation could make a `setInterval` method call itself by shadowing the global. The article reports that Babel maintainers fixed the issues and describes the plugin as a relatively straightforward way to preserve the existing build workflow.

### Source excerpt

By Kevin Barabash We've been using ES6 (along with JSX) for sometime at Khan Academy. Right now, we're ... Read more

## Choosing Wisely: for vs. forEach in Kotlin (A Thinking Dev's Perspective)

DevFeed: [Choosing Wisely: for vs. forEach in Kotlin (A Thinking Dev's Perspective)](<https://devfeed.tech/articles/choosing-wisely-for-vs-foreach-in-kotlin-a-thinking-dev-s-perspective-24905.md>)

Original publisher: [Read original article](<https://blog.blundellapps.co.uk/choosing-wisely-for-vs-foreach-in-kotlin-a-thinking-devs-perspective/>)

Author: blundell

Published: 2025-04-04T14:25:30Z

Content type: article

Language: en

Sources: [Blundell](<https://devfeed.tech/sources/blundell.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [androiddev](<https://devfeed.tech/tags/androiddev.md>), [code](<https://devfeed.tech/tags/code.md>), [dev](<https://devfeed.tech/tags/dev.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [functional](<https://devfeed.tech/tags/functional.md>), [intermediate](<https://devfeed.tech/tags/intermediate.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [loops](<https://devfeed.tech/tags/loops.md>), [programming](<https://devfeed.tech/tags/programming.md>), [readability](<https://devfeed.tech/tags/readability.md>), [reference](<https://devfeed.tech/tags/reference.md>), [reference-androiddev-kotlin](<https://devfeed.tech/tags/reference-androiddev-kotlin.md>), [structure](<https://devfeed.tech/tags/structure.md>), [syntax](<https://devfeed.tech/tags/syntax.md>)

### AI overview

This Kotlin development article argues against reflexively choosing forEach. It compares forEach with traditional for loops and dedicated functional operators, emphasizing readability, explicit control, side effects, and clearer data flow.

### Source excerpt

The forEach loop, are you using it without thinking? In Kotlin, empirically forEach is often the go-to loop, it's pragmatically close at reach in the IDE auto-complete, but is it always the right choice? This post argues that for loops deserve more consideration, offering clarity and control that forEach sometimes lacks. Let's discuss why a [...] The post Choosing Wisely: for vs. forEach in Kotlin (A Thinking Dev's Perspective) first appeared on Blundell.

## Version 0.6.5 changelog: new datatypes, codecs, and runtime features

DevFeed: [Version 0.6.5 changelog: new datatypes, codecs, and runtime features](<https://devfeed.tech/articles/0-6-5-changelog-22386.md>)

Original publisher: [Read original article](<https://www.red-lang.org/2024/02/065-changelog.html>)

Author: Nenad Rakocevic (noreply@blogger.com)

Published: 2024-02-19T15:22:00Z

Content type: release

Language: en

Sources: [Red](<https://devfeed.tech/sources/red.md>)

Topics: [changelog](<https://devfeed.tech/topics/changelog.md>), [version](<https://devfeed.tech/topics/version.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [Pull Request](<https://devfeed.tech/topics/pull-request.md>)

Tags: [allows](<https://devfeed.tech/tags/allows.md>), [apply](<https://devfeed.tech/tags/apply.md>), [async](<https://devfeed.tech/tags/async.md>), [branch](<https://devfeed.tech/tags/branch.md>), [changelog](<https://devfeed.tech/tags/changelog.md>), [codec](<https://devfeed.tech/tags/codec.md>), [csv](<https://devfeed.tech/tags/csv.md>), [debugger](<https://devfeed.tech/tags/debugger.md>), [deflate](<https://devfeed.tech/tags/deflate.md>), [doc](<https://devfeed.tech/tags/doc.md>), [docs](<https://devfeed.tech/tags/docs.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [github](<https://devfeed.tech/tags/github.md>), [gpio](<https://devfeed.tech/tags/gpio.md>), [high-performance](<https://devfeed.tech/tags/high-performance.md>), [instrumentation](<https://devfeed.tech/tags/instrumentation.md>), [io](<https://devfeed.tech/tags/io.md>), [ipv6](<https://devfeed.tech/tags/ipv6.md>), [json](<https://devfeed.tech/tags/json.md>), [new-features](<https://devfeed.tech/tags/new-features.md>), [release](<https://devfeed.tech/tags/release.md>)

### AI overview

Version 0.6.5 follows a breaking syntax change and gathers changes across about 5,000 commits; the project says automatic builds are produced for each new master commit rather than specific version builds. Major additions include money!, ref!, point2D! and point3D! datatypes; Redbin, JSON and CSV codecs; a high-performance runtime lexer and interpreter instrumentation for debugging, tracing and profiling; APPLY and dynamic refinements; compression and Raspberry Pi GPIO support; and raw strings. The excerpt also reports map! enhancements, faster context lookups, a cross-platform threading library, and improvements to standard-library and garbage-collector stability. Async I/O ports with IPv6!, a TextUI backend for View and an XML codec are described as finished or nearly finished in branches or PRs.

### Source excerpt

Bumping up the version number was motivated by the breaking syntax change done recently. We do not offer specific builds for a given version number anymore since we provide automatic builds (with builds history) on each new master commit. Though, the changelog for new version number changes will still be provided...and this one is pretty big as it covers about 5000 commits! Hope this will help users who might have missed some changes to catch up. 613 PRs were merged, 2415 fix commits were pushed, among which 902 are closing issues tracked on Github. The most notable new features and changes are listed below with eventual links to docs or previous blog posts describing or mentioning them: Main new features New datatypes: money!, ref!, point2D!, point3D!. New codecs: Redbin, JSON, CSV New high-performance run-time lexer with instrumentation support.(blog)(doc) Interpreter instrumentation support (debugger, tracer, profiler).(doc) New powerful APPLY native, with deep interpreter support.(blog) Dynamic refinements support.(blog) Adds compress and uncompress natives with gzib, zlib and deflate algorithms support. Adds gpio:// port with GPIO dialect for RaspberryPi.(blog) Adds TAB navigation support to View. (blog) Adds raw strings syntax support.(doc) Swaps map! and construction syntax. (blog) Hashtables are now used for fast lookups in contexts. Custom dtoa library implementation to load and form float values. Standard library and garbage collector stability vastly improved. Finished or almost finished features in branches:: Full IO ports with async support, including new IPv6! datatype.(branch) TextUI backend to View.(PR) XML codec.(PR) Other general new features or changes New natives: TRANSCODE, SCAN, AS-MONEY, ENHEX. New functions: SINGLE?, LAST?, DT, TRANSCODE-TRACE, TRACE, CLOCK, NO-REACT, DO-NO-SYNC New routines: SET-TRACE, TRACING? Extends EMPTY? to support map! values. Allows NONE as value in map!. Adds REMOVE/KEY support for removing map! entries. Adds FOREACH

## PHP Foreach: All You Need to Know

DevFeed: [PHP Foreach: All You Need to Know](<https://devfeed.tech/articles/php-foreach-all-you-need-to-know-121172.md>)

Original publisher: [Read original article](<https://wpshout.com/php-foreach/>)

Author: David Hayes

Published: 2019-10-01T14:49:58Z

Content type: article

Language: en

Sources: [Back-End Development - WPShout](<https://devfeed.tech/sources/back-end-development-wpshout.md>)

Topics: [PHP](<https://devfeed.tech/topics/php.md>), [iteration](<https://devfeed.tech/topics/iteration.md>), [conditionals](<https://devfeed.tech/topics/conditionals.md>)

Tags: [array](<https://devfeed.tech/tags/array.md>), [arrays](<https://devfeed.tech/tags/arrays.md>), [back-end-development](<https://devfeed.tech/tags/back-end-development.md>), [filter](<https://devfeed.tech/tags/filter.md>), [flow](<https://devfeed.tech/tags/flow.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [php](<https://devfeed.tech/tags/php.md>), [wps](<https://devfeed.tech/tags/wps.md>), [wps-nf](<https://devfeed.tech/tags/wps-nf.md>)

### AI overview

PHP `foreach` iterates through an array or an object's visible properties, making it useful for processing lists and key-value data. The excerpt shows basic iteration, collecting selected values by appending with `$array[]`, accessing keys and values with `as $key => $value`, and traversing arrays of arrays. It distinguishes `continue`, which skips the remaining work for the current item and moves to the next, from `break`, which ends the loop entirely. The article also contrasts `foreach` over an existing collection with `for` loops, which it presents as more suited to counting through a numeric sequence. It notes that classes can customize iteration with `Iterator` or `IteratorAggregate`, but does not cover those further.

### Source excerpt

One of the most-used language constructs in my life with PHP is foreach. Partly, this is because it's just an exquisitely named language construct, and it maps well to how I think. Partly this is because it's kind of the backbone of a webpage: iterate through a set of things, operating on some selectively, and... Read More "PHP Foreach: All You Need to Know

## Building a Sandbox Dashboard Pt. 2: Adding a Transactions List

DevFeed: [Building a Sandbox Dashboard Pt. 2: Adding a Transactions List](<https://devfeed.tech/articles/building-a-sandbox-dashboard-pt-2-adding-a-transactions-list-15559.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/building-a-sandbox-dashboard-pt-2-adding-a-transactions-list>)

Author: Tristan Sokol

Published: 2017-06-16T18:52:40Z

Content type: tutorial

Language: en

Sources: [Square Corner](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [Transactions](<https://devfeed.tech/topics/transactions.md>)

Tags: [access-tokens](<https://devfeed.tech/tags/access-tokens.md>), [account](<https://devfeed.tech/tags/account.md>), [api](<https://devfeed.tech/tags/api.md>), [apis](<https://devfeed.tech/tags/apis.md>), [building](<https://devfeed.tech/tags/building.md>), [dashboard](<https://devfeed.tech/tags/dashboard.md>), [display](<https://devfeed.tech/tags/display.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [functionality](<https://devfeed.tech/tags/functionality.md>), [header](<https://devfeed.tech/tags/header.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [id](<https://devfeed.tech/tags/id.md>), [information](<https://devfeed.tech/tags/information.md>), [list](<https://devfeed.tech/tags/list.md>), [navigation](<https://devfeed.tech/tags/navigation.md>), [reporting](<https://devfeed.tech/tags/reporting.md>), [sandbox](<https://devfeed.tech/tags/sandbox.md>), [series](<https://devfeed.tech/tags/series.md>), [transaction](<https://devfeed.tech/tags/transaction.md>), [transactions](<https://devfeed.tech/tags/transactions.md>)

### AI overview

The tutorial adds a Transactions page to a sandbox Square Dashboard and uses Square's Transactions API to list transactions for the selected location. It configures the API with an access token stored in the session, calls `listTransactions`, and renders each result's creation time, refund status, first tender's note and amount, and transaction ID in rows. The author cautions that exposing access tokens on the client side is for tutorial purposes only and should not be done in production. The displayed fields are a snapshot of the available transaction information.

### Source excerpt

Following Part 1 of our series building out a sandbox Dashboard, we'll show you how to add transaction reporting functionality.

## Functional operations with collections in Kotlin (KAD 11)

DevFeed: [Functional operations with collections in Kotlin (KAD 11)](<https://devfeed.tech/articles/functional-operations-with-collections-in-kotlin-kad-11-27166.md>)

Original publisher: [Read original article](<https://antonioleiva.com/functional-operations-collections-kotlin>)

Published: 2017-02-02T00:00:00Z

Content type: tutorial

Language: en

Sources: [Antonio Leiva](<https://devfeed.tech/sources/antonio-leiva.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Code](<https://devfeed.tech/topics/code.md>), [Android](<https://devfeed.tech/topics/android.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [collections](<https://devfeed.tech/tags/collections.md>), [filter](<https://devfeed.tech/tags/filter.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [functional](<https://devfeed.tech/tags/functional.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [list](<https://devfeed.tech/tags/list.md>), [map](<https://devfeed.tech/tags/map.md>), [sorting](<https://devfeed.tech/tags/sorting.md>)

### AI overview

This tutorial introduces functional operations on Kotlin collections, including forEach, map, filter, first, last, and sorting. It explains how these operations simplify collection handling compared with Java and notes alternatives such as nullable results when no matching element is found.

### Source excerpt

Everything Android, Kotlin and other random topics

## Dining Philosophers in Java 8

DevFeed: [Dining Philosophers in Java 8](<https://devfeed.tech/articles/dining-philosophers-in-java-8-32218.md>)

Original publisher: [Read original article](<https://bruceeckel.com/2016/12/29/dining-philosophers-in-java-8/>)

Author: Bruce Eckel

Published: 2016-12-29T00:00:00Z

Content type: article

Language: en

Sources: [Bruce Eckel - Computing Thoughts](<https://devfeed.tech/sources/bruce-eckel-computing-thoughts.md>)

Topics: [Deadlock](<https://devfeed.tech/topics/deadlock.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Java](<https://devfeed.tech/topics/java.md>), [locking](<https://devfeed.tech/topics/locking.md>), [async](<https://devfeed.tech/topics/async.md>), [ExecutorService](<https://devfeed.tech/topics/executorservice.md>)

Tags: [arrays](<https://devfeed.tech/tags/arrays.md>), [chopsticks](<https://devfeed.tech/tags/chopsticks.md>), [class](<https://devfeed.tech/tags/class.md>), [collection](<https://devfeed.tech/tags/collection.md>), [collections](<https://devfeed.tech/tags/collections.md>), [completablefuture](<https://devfeed.tech/tags/completablefuture.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [concurrent](<https://devfeed.tech/tags/concurrent.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [deadlock](<https://devfeed.tech/tags/deadlock.md>), [deadlocks](<https://devfeed.tech/tags/deadlocks.md>), [debug](<https://devfeed.tech/tags/debug.md>), [dijkstra](<https://devfeed.tech/tags/dijkstra.md>), [executor](<https://devfeed.tech/tags/executor.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [forks](<https://devfeed.tech/tags/forks.md>), [java](<https://devfeed.tech/tags/java.md>), [java-8](<https://devfeed.tech/tags/java-8.md>), [tasks](<https://devfeed.tech/tags/tasks.md>)

### AI overview

The Java example shows how philosophers can deadlock when each takes a right chopstick and then waits for the left, creating circular wait. A `StickHolder` uses a size-one `BlockingQueue` to ensure only one philosopher can hold a chopstick at a time; philosophers block in `take()` until it is returned. The program may appear to run correctly before deadlocking, and adding thinking time or philosophers makes deadlock less likely without eliminating the underlying risk. The example breaks circular wait by reversing the chopstick order for one philosopher, so that philosopher takes the left stick first. The text notes that deadlock can also be prevented by breaking any of its four necessary conditions, and that avoiding shared resources is easiest when feasible.

### Source excerpt

Because tasks can become blocked, it's possible for one task to get stuck waiting for another task, which in turn waits for another task, and so on, until the chain leads back to a task waiting on the first one. You get a continuous loop of tasks waiting on each other, and no one can move. This is called deadlock.1 If you try running a program and it deadlocks right away, you can immediately track down the bug.

## Are Java 8 Lambdas Closures?

DevFeed: [Are Java 8 Lambdas Closures?](<https://devfeed.tech/articles/are-java-8-lambdas-closures-32211.md>)

Original publisher: [Read original article](<https://bruceeckel.com/2015/10/17/are-java-8-lambdas-closures/>)

Author: Bruce Eckel

Published: 2015-10-17T00:00:00Z

Content type: article

Language: en

Sources: [Bruce Eckel - Computing Thoughts](<https://devfeed.tech/sources/bruce-eckel-computing-thoughts.md>)

Topics: [Closure](<https://devfeed.tech/topics/closure.md>), [Functional programming](<https://devfeed.tech/topics/functional-programming.md>)

Tags: [2015](<https://devfeed.tech/tags/2015.md>), [abstraction](<https://devfeed.tech/tags/abstraction.md>), [behavior](<https://devfeed.tech/tags/behavior.md>), [bytecode](<https://devfeed.tech/tags/bytecode.md>), [closure](<https://devfeed.tech/tags/closure.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [data](<https://devfeed.tech/tags/data.md>), [external](<https://devfeed.tech/tags/external.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [function](<https://devfeed.tech/tags/function.md>), [functional](<https://devfeed.tech/tags/functional.md>), [functional-programming](<https://devfeed.tech/tags/functional-programming.md>), [functions](<https://devfeed.tech/tags/functions.md>), [haskell](<https://devfeed.tech/tags/haskell.md>), [java](<https://devfeed.tech/tags/java.md>), [java-8](<https://devfeed.tech/tags/java-8.md>)

### AI overview

Java 8 lambdas can capture local values from their surrounding scope, so they act as closures with a key restriction: captured local variables must be final or effectively final. The article illustrates that a captured integer can be read but not reassigned or updated inside the lambda. A mutable heap object can still be changed through a captured reference, though that introduces mutable shared state concerns if used concurrently. It frames lambdas as a way to create and pass functions at runtime and contrasts this with Python's mutable closed-over variable example.

### Source excerpt

(Significantly rewritten 11/25/2015) Based on what I've heard, I was surprised to discover that the short answer is "yes, with a caveat that, after explanation, isn't terrible." So, a qualified yes. For the longer answer, we must first explore the question of "why, again, are we doing all this?" Abstraction over Behavior The simplest way to look at the need for lambdas is that they describe what computation should be performed, rather than how it should be performed.

## Getting the current filename with Spark and HDFS

DevFeed: [Getting the current filename with Spark and HDFS](<https://devfeed.tech/articles/getting-the-current-filename-with-spark-and-hdfs-20849.md>)

Original publisher: [Read original article](<http://themodernlife.net/scala/spark/hadoop/hdfs/2014/09/28/spark-input-filename/>)

Published: 2014-09-28T11:50:13Z

Content type: tutorial

Language: en

Sources: [Ian Hummel](<https://devfeed.tech/sources/ian-hummel.md>)

Topics: [Apache Spark](<https://devfeed.tech/topics/spark.md>), [Hadoop](<https://devfeed.tech/topics/hadoop.md>)

Tags: [apache-spark](<https://devfeed.tech/tags/apache-spark.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [hadoop](<https://devfeed.tech/tags/hadoop.md>), [hdfs](<https://devfeed.tech/tags/hdfs.md>), [map](<https://devfeed.tech/tags/map.md>), [reduce](<https://devfeed.tech/tags/reduce.md>), [scala](<https://devfeed.tech/tags/scala.md>), [spark](<https://devfeed.tech/tags/spark.md>), [subclass](<https://devfeed.tech/tags/subclass.md>)

### AI overview

A tutorial shows how to obtain the filename being processed in a Spark map/reduce job. It uses Spark 1.1.0's HadoopRDD.mapPartitionsWithInputSplit with FileSplit, and notes that the approach requires an InputFormat subclass of FileInputFormat.

### Source excerpt

It's occasionally useful when writing map/reduce jobs to get a hold of the current filename that's being processed. There's a few ways to do this, depending on the version of Spark that you're using. Spark 1.1.0 introduced a new method on HadoopRDD that makes this super easy: import org.apache.hadoop.io.LongWritable import org.apache.hadoop.io.Text import org.apache.hadoop.mapred.{FileSplit, TextInputFormat} import org.apache.spark.rdd.HadoopRDD // Create the text file val text = sc.hadoopFile("file:///tmp/files", classOf[TextInputFormat], classOf[LongWritable], classOf[Text], sc.defaultMinPartitions) // text: org.apache.spark.rdd.RDD[(org.apache.hadoop.io.LongWritable, org.apache.hadoop.io.Text)] = file:///tmp/files HadoopRDD[2] at hadoopFile at <console>:16 // Cast to a HadoopRDD val hadoopRdd = text.asInstanceOf[HadoopRDD[LongWritable, Text]] // hadoopRdd: org.apache.spark.rdd.HadoopRDD[org.apache.hadoop.io.LongWritable,org.apache.hadoop.io.Text] = file:///tmp/files HadoopRDD[2] at hadoopFile at <console>:16 val fileAndLine = hadoopRdd.mapPartitionsWithInputSplit { (inputSplit, iterator) ⇒ val file = inputSplit.asInstanceOf[FileSplit] iterator.map { tpl ⇒ (file.getPath, tpl._2) } } fileAndLine.foreach(println) // prints lines like (file:/tmp/files/part-00000,line1...), (file:/tmp/files/part-00000,line2...), ... There are a few things to note: - You can't simply use sc.textFile because under the hood, the textFile method actually maps the resulting HadoopRDD, returning a MappedRDD which is not what we want - This will only work if your InputFormat is a subclass of FileInputFormat - mapPartitionsWithInputSplit returns a new iterator, in this case we simply map over it (which is done lazily!) to include the split's filename

## Your First Polyfill

DevFeed: [Your First Polyfill](<https://devfeed.tech/articles/your-first-polyfill-52597.md>)

Original publisher: [Read original article](<http://www.jackfranklin.co.uk/blog/writing-javascript-polyfill/>)

Published: 2012-06-20T00:00:00Z

Content type: tutorial

Language: en

Sources: [Jack Franklin](<https://devfeed.tech/sources/jack-franklin.md>)

Topics: [polyfill](<https://devfeed.tech/topics/polyfill.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [forEach](<https://devfeed.tech/topics/foreach.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>)

Tags: [array](<https://devfeed.tech/tags/array.md>), [browser](<https://devfeed.tech/tags/browser.md>), [ecmascript](<https://devfeed.tech/tags/ecmascript.md>), [fallback](<https://devfeed.tech/tags/fallback.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [html5](<https://devfeed.tech/tags/html5.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [js](<https://devfeed.tech/tags/js.md>), [mdn](<https://devfeed.tech/tags/mdn.md>), [polyfill](<https://devfeed.tech/tags/polyfill.md>), [polyfills](<https://devfeed.tech/tags/polyfills.md>)

### AI overview

A polyfill supplies a fallback when a browser lacks a feature; the tutorial recommends checking for native support before adding one. Its illustrative Array.prototype.forEach implementation validates that the callback is a function, saves the array length, then calls the callback for each item with the item, index, and array. It uses callback.call(thisArg, ...) to set the callback's this value. The author notes this is a deliberately simple, incomplete implementation and points to MDN for a more comprehensive version.

### Source excerpt

In today's tutorial I want to introduce you to the concepts behind polyfills, a word you see used a lot in today's JS world. I'll demonstrate just what a polyfill is and then write one ourselves. A polyfill is a piece of code that provides a fallback if a certain feature doesn't exist within that browser's JS engine. Polyfills usually follow a pattern. First, they check to see if the function they implement exists, and then we only write our fallback implementation if we have to. There are multiple polyfills out there for mutliple functions. The website HTML5 Please is very useful for finding polyfills to do a particular job. Now, lets get to our own implementation. I should note as this point that this implementation is by no means going to be a fully fledged, comprehensive one. At the end, I'll link you to the Mozilla Documentation Network (or MDN) page that contains a hugely comprehensive & fully featured polyfill, should you require it. Today we'll be implementing Array forEach, which was introduced in JavaScript 1.6, ECMAScript 5th edition. In reality, this is actually a very well supported feature, but I've chosen it more for the fact that it's a fairly simple implementation. The first thing we need to do is see if the method has been natively implemented. We do this by checking to see if Array.prototype.forEach != undefined. If it is indeed undefined, we can continue. What this function does is iterate through all items within an array and call a function on them. This function is passed 3 arguments: the item, the index & the array it's iterating on. It's also possible to pass in to forEach a second value, which will be used as the value for this within the callback. With that in mind, lets implement it! At this point, I'm presuming the method is not natively supported, and we need to implement it. Our first line simply defines the function: Array.prototype.forEach = function(callback, thisArg) { Next, we need to check if callback is a function or not, and th

## Extend Math.round, Math.ceil and Math.floor to allow for precision

DevFeed: [Extend Math.round, Math.ceil and Math.floor to allow for precision](<https://devfeed.tech/articles/extend-math-round-math-ceil-and-math-floor-to-allow-for-precision-51935.md>)

Original publisher: [Read original article](<https://lea.verou.me/2009/02/extend-mathround-mathceil-and-mathfloor-to-allow-precision/>)

Author: Lea Verou

Published: 2009-02-12T00:00:00Z

Content type: tutorial

Language: en

Sources: [Lea Verou's blog](<https://devfeed.tech/sources/lea-verou-s-blog.md>)

Topics: [Mathematics](<https://devfeed.tech/topics/mathematics.md>), [Closure](<https://devfeed.tech/topics/closure.md>), [bestpractice](<https://devfeed.tech/topics/bestpractice.md>)

Tags: [array](<https://devfeed.tech/tags/array.md>), [blog](<https://devfeed.tech/tags/blog.md>), [closure](<https://devfeed.tech/tags/closure.md>), [code](<https://devfeed.tech/tags/code.md>), [conditional](<https://devfeed.tech/tags/conditional.md>), [dry](<https://devfeed.tech/tags/dry.md>), [foreach](<https://devfeed.tech/tags/foreach.md>), [function](<https://devfeed.tech/tags/function.md>), [functions](<https://devfeed.tech/tags/functions.md>), [js](<https://devfeed.tech/tags/js.md>), [math](<https://devfeed.tech/tags/math.md>), [original](<https://devfeed.tech/tags/original.md>), [performance](<https://devfeed.tech/tags/performance.md>), [precision](<https://devfeed.tech/tags/precision.md>), [prototype](<https://devfeed.tech/tags/prototype.md>), [tests](<https://devfeed.tech/tags/tests.md>), [variables](<https://devfeed.tech/tags/variables.md>)

### AI overview

The excerpt proposes extending Math.round, Math.ceil, and Math.floor with a precision argument by scaling the number by 10^precision, applying the saved native function, then scaling back. It says omitted or falsy precision defaults to zero, preserving the original integer behavior. To avoid duplicating wrapper code, it shows looping over the function names; a closure keeps loop variables out of the global namespace, while a forEach version is offered as a more readable alternative when available. The author reports the wrappers took about twice as long as native calls in their tests; a conditional fast path for zero precision offered little improvement and slowed calls with positive precision. The excerpt does not establish behavior for broader numeric edge cases.

### Source excerpt

Math.round, Math.ceil and Math.floor are very useful functions. However, when using them, I find myself many times needing to specify a precision level. You don't always want to round to an integer, you often just want to strip away some of the decimals. We probably all know that if we have a function to round to integers, we can round to X decimals by doing Math.round(num*Math.pow(10,X)) / Math.pow(10,X). This kind of duck typing can get tedious, so usually, you roll your own function to do that. However, why not just add that extra functionality to the functions that already exist and you're accustomed to? Let's start with Math.round. It's the most needed one anyway. Firstly we'll have to store the native function somewhere, since we're going to replace it. So we do something along the lines of: Math._round = Math.round; Now let's sigh replace the native Math.round with our own: Math.round = function(number, precision) { precision = Math.abs(parseInt(precision)) || 0; var coefficient = Math.pow(10, precision); return Math._round(number*coefficient)/coefficient; } And guess what? It still works the old way too, so your old scripts won't break. So now, let's go to Math.ceil and Math.floor. If you notice, the only thing that changes is the function name. Everything else is the same. So, even though we could copy-paste the code above and change the names, we would end up with triple the size of the code that we need and we would have also violated the DRY principle. So we could put the names of the functions in an array, and loop over it instead: (function(){ var MathFns = ['round', 'floor', 'ceil' ]; for(var i = MathFns.length; i>-1; i--) { Math['_' + MathFns[i]] = Math[MathFns[i]]; Math[MathFns[i]] = function(number, precision) { precision = Math.abs(parseInt(precision)) || 0; var coefficient = Math.pow(10, precision); return Math['_' + MathFns[i]](number*coefficient)/coefficient; } } })(); Why the closure? To allow us to be free in defining our variables without po