Language Design: Naming Conventions

Part 4: Streaming (WIP)

Published on 2022-06-08. Last updated on 2022-07-26
Name Example Explanation
map

flatMap

mapAndFlatten

Filters

Name Example Explanation
get(index)
  • returns the element with the given index of the stream
first
  • returns the first element of the stream
last
  • returns the last element of the stream
take(amount)
  • returns a stream that produces the first amount elements of the original stream
takeWhile(predicate)
  • returns a stream that produces elements until the predicate evaluates to false
drop(amount)
  • returns a stream without the first amount elements of the original stream
dropWhile(predicate)

accept(predicate)

select(predicate)

  • returns a stream that produces only elements for which predicate evaluates to true
  • sometimes called filter, which is a poor name as it's unclear (especially for non-native speakers) whether "filtered elements" are those retained, or those "filtered out"
  • accept is not ideal, as the visitor pattern also makes use of this name
  • select is even less ideal, as SQL uses the name for a completely different purpose
reject(predicate)
  • returns a stream that produces only elements for which predicate evaluates to false
  • sometimes called filterNot, which is a poor name as it's unclear (especially for non-native speakers) whether "filtered elements" are those retained, or those "filtered out"
distinct
  • returns a stream that produces only the first occurrence of elements occurring multiple times

Folds

Name Example Explanation
fold(fun, startValue)
reduce(fun)
combine[Monoid]

sum[Numeric]

product[Numeric]

average[Numeric]

forAll(predicate)
forAny(predicate)
forNone(predicate)

Injects

Name Example Explanation
joinInner[Record]
joinLeft[Record]
joinRight[Record]
joinFull[Record]
groupBy(function)
partitionBy(function)

Fan-Ins

Name Example Explanation
concat
  • returns a stream that produces the values from the first stream and then the values of the second stream
interleave
  • returns a stream that produces a value, alternating between the first and second stream
  • likely requires multiple method variants that handle streams of different lengths in different ways
zip
  • returns a stream that produces a tuple value, where the first element is from the first stream and the second element is from the second stream
  • likely requires multiple method variants that handle streams of different lengths in different ways
zipWithIndex
  • returns a stream that produces a tuple value, where the first element is from the stream and the second element is the index at which the value was produced