import * as tracing_1 from "../../../../Tracing"
import * as tracing_2 from "../../../../Tracing"
const fileName_1 =
  "(@effect-ts/system): _src/Collections/Immutable/Chunk/api/filterMap.ts"
import * as O from "../../../../Option"
import * as Chunk from "../core"
import * as ChunkDef from "../definition"
/**
 * Returns a filtered, mapped subset of the elements of this chunk.
 */

export function filterMap_(self, f) {
  switch (self._typeId) {
    case ChunkDef.ArrTypeId: {
      const array = self.arrayLike()
      let dest = Chunk.empty()

      for (let i = 0; i < array.length; i++) {
        const rhs = f(array[i])

        if (O.isSome(rhs)) {
          dest = Chunk.append_(dest, rhs.value)
        }
      }

      return dest
    }

    default: {
      return filterMap_(self.materialize(), f)
    }
  }
}
/**
 * Returns a filtered, mapped subset of the elements of this chunk.
 *
 * @dataFirst filterMap_
 */

export function filterMap(f) {
  return (self) => filterMap_(self, f)
}
//# sourceMappingURL=filterMap.js.map
