mirror of
https://github.com/github/semantic.git
synced 2025-01-06 06:46:07 +03:00
Implement iter
as a method.
This commit is contained in:
parent
c0edc77185
commit
8226285153
@ -21,6 +21,12 @@ public enum Free<A, B> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func iter(transform: Syntax<B, A> -> B) -> B {
|
||||||
|
return analysis(
|
||||||
|
ifPure: id,
|
||||||
|
ifRoll: { transform($0.map { Free.iter($0)(transform) }) })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: Functor
|
// MARK: Functor
|
||||||
|
|
||||||
@ -71,10 +77,3 @@ extension Free where A: Hashable, B: Hashable {
|
|||||||
return hash(ifPure: Hash.init, ifRoll: Hash.init)
|
return hash(ifPure: Hash.init, ifRoll: Hash.init)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public func iter<A, B>(transform: Syntax<B, A> -> B)(_ free: Free<A, B>) -> B {
|
|
||||||
return free.analysis(
|
|
||||||
ifPure: id,
|
|
||||||
ifRoll: { transform($0.map(iter(transform))) })
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user