How to resolve the algorithm Apply a callback to an array step by step in the ooRexx programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Apply a callback to an array step by step in the ooRexx programming language

Table of Contents

Problem Statement

Take a combined set of elements and apply a function to each element.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Apply a callback to an array step by step in the ooRexx programming language

Source code in the oorexx programming language

start = .array~of("Rick", "Mike", "David", "Mark")
new = map(start, .routines~reversit)
call map new, .routines~sayit


-- a function to perform an iterated callback over an array
-- using the provided function.  Returns an array containing
-- each function result
::routine map
  use strict arg array, function
  resultArray = .array~new(array~items)
  do item over array
     resultArray~append(function~call(item))
  end
  return resultArray

::routine reversit
  use arg string
  return string~reverse

::routine sayit
  use arg string
  say string
  return .true   -- called as a function, so a result is required

  

You may also check:How to resolve the algorithm String interpolation (included) step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Terminal control/Cursor movement step by step in the Go programming language
You may also check:How to resolve the algorithm Align columns step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the Julia programming language
You may also check:How to resolve the algorithm Self-describing numbers step by step in the CLU programming language