MCPcopy
hub / github.com/Effect-TS/effect / changeMap

Function changeMap

packages/effect/src/SchemaAST.ts:2743–2755  ·  view source on GitHub ↗
(as: ReadonlyArray<A>, f: (a: A) => A)

Source from the content-addressed store, hash-verified

2741): Arr.NonEmptyReadonlyArray<A>
2742function changeMap<A>(as: ReadonlyArray<A>, f: (a: A) => A): ReadonlyArray<A>
2743function changeMap<A>(as: ReadonlyArray<A>, f: (a: A) => A): ReadonlyArray<A> {
2744 let changed = false
2745 const out = Arr.allocate(as.length) as Array<A>
2746 for (let i = 0; i < as.length; i++) {
2747 const a = as[i]
2748 const fa = f(a)
2749 if (fa !== a) {
2750 changed = true
2751 }
2752 out[i] = fa
2753 }
2754 return changed ? out : as
2755}
2756
2757/**
2758 * Returns the from part of a transformation if it exists

Callers 3

mutableFunction · 0.85
typeASTFunction · 0.85
encodedAST_Function · 0.85

Calls 1

fFunction · 0.70

Tested by

no test coverage detected