#!/bin/bash
# shellcheck disable=SC2155
if ! type "include" > /dev/null 2>&1; then
  include() {
  . "$(cd "$(dirname "$1")" && pwd)/${2}";
  };
fi
include "${BASH_SOURCE[0]}" ../pragma_once.bash
if ! pragma_once ${BASH_SOURCE[0]}; then return 0; fi
include "${BASH_SOURCE[0]}" ./global_rely/export.bash
# shellcheck source=./global_rely/export.bash




square() {
  echo $(($1 * $1))
}

cube() {
  echo $(($1 * $1 * $1))
}

add() {
  echo $(($1 + $2))
}

map() {
  local fn=$1
  while read value; do
    $fn $value
  done
}

reduce() {
  local fn=$1
  local result=${2:-0} # 初始值
  while read value; do
    result=$($fn $result $value)
  done
  echo $result
}

#seq 1 10 | map square | reduce add # 平方和：385
#seq 1 10 | map cube | reduce add   # 立方和：3025

return 0