<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Autumn on Medium]]></title>
        <description><![CDATA[Stories by Autumn on Medium]]></description>
        <link>https://medium.com/@autumn.bom?source=rss-a54053abb683------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4bSozz71WNtZdNW0Kf43JA.jpeg</url>
            <title>Stories by Autumn on Medium</title>
            <link>https://medium.com/@autumn.bom?source=rss-a54053abb683------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 05:34:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@autumn.bom/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Scott Wlaschin — Talk Session: Domain Modeling Made Functional]]></title>
            <link>https://medium.com/@autumn.bom/scott-wlaschin-talk-session-domain-modeling-made-functional-ef6fa48ed4be?source=rss-a54053abb683------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef6fa48ed4be</guid>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[functional-programming]]></category>
            <dc:creator><![CDATA[Autumn]]></dc:creator>
            <pubDate>Wed, 06 Dec 2023 14:45:17 GMT</pubDate>
            <atom:updated>2023-12-06T15:02:01.547Z</atom:updated>
            <content:encoded><![CDATA[<h3>Scott Wlaschin — Talk Session: Domain Modeling Made Functional</h3><h4>Composable Type System</h4><p>최근 몇 년 동안, 도메인 주도 설계(DDD)에 흥미를 가지고 탐구해보고 있습니다. 아직 부족하지만, 지난 경험을 바탕으로 제가 느끼는것은 계속해서 진화하며 복잡해지는 해결해야할 문제 영역을 다루는 기술로 참여자들이 모두 동일한 언어와 모델을 이해하며, 이를 자신들의 영역에 맞게 표현하는 것이 중요한 점이라고 생각하고 있습니다</p><p>이번에 소개할 영상은 Scott Wlaschin 이 2019 Explore DDD 컨퍼런스에서 발표한 ‘Domain Modeling Made Functional’ 인데요, 상대적으로 익숙한 OOP 에서는 클래스와 상속을 사용하는 반면, FP 에서는 도메인을 어떻게 모델링하는지 살펴보다 발견한 영상으로 FP 와 DDD 의 교집합을 다루면서 이 둘이 어떻게 잘 어울리며 어떤 좋은점이 있는지에 대해 설명하고 있으며 정적 타입의 함수형 언어인 F#의 코드를 사용하여 FP 에서 전술적 도메인 모델링을 하는 방법에 대한 내용을 소개하고 있습니다.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FPLFl95c-IiU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPLFl95c-IiU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPLFl95c-IiU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fff19ad5b3afc49e31b2ebf1807f7ace/href">https://medium.com/media/fff19ad5b3afc49e31b2ebf1807f7ace/href</a></iframe><p>영상에서 소프트웨어 개발 과정을 Input -&gt; Process -&gt; Output으로 표현하고 있습니다. 일반적으로 개발자들은 주로 Process 단계에 집중하여 언어, 도구, 에디터, CI, TDD 등에 대해 이야기하지만 사실 이 단계에서 코딩과 테스팅은 그리 중요하지 않다고 말합니다. 대신 발표자 자신이 중요하게 생각하는 문제는 Garbage Input 이 들어갔을 때 Garbage Output 이 나오는 것으로 아무리 최고의 언어와 도구를 사용한다 해도 잘못된 요구사항과 입력이 들어오면 올바른 결과를 얻기 어렵습니다. 따라서 이 문제를 해결하기 위해서는 올바른 요구사항과 모델링이 중요하며, 이것이 설계의 목표라고 강조합니다.</p><p>그렇다면 어떻게 (코딩이 아닌) 설계를 제대로 할 수 있을까요? 발표자는 애자일과 DDD를 언급합니다. 애자일에서는 Rapid Feedback 을 통해 빠르게 학습하고 그 피드백을 받아들여 반복하는 과정을 설명하며 이러한 접근은 코딩하는 단계뿐만 아니라 설계 단계에서도 동일하게 적용될 수 있다고 말합니다. DDD에서는 참여자들이 공유된 Mental Model을 갖는 것을 중요하게 보며, 구현되는 코드는 이 모델을 반영하여 개발자 외의 다른 참여자들도 코드를 보고 이해할 수 있도록 하는것을 말하고 있습니다.</p><blockquote>domain model == code == documentation</blockquote><p>그렇다면 도메인 모델을 정말로 코드로 표현할 수 있을까요? 발표에서는 CardGame 을 예시로 들어 실제 동작하는 코드를 통해 CardGame 의 모델과 규칙을 설명하며, 개발자가 아닌 참여자들도 코드를 보고 이해하면서 빠진 개념을 채워넣거나 개념을 좀 더 구체화하는 과정을 보여주고 있습니다. 이러한 코딩이 아닌 설계 단계에서 모두가 참여하여 빠르게 확인하는 것은 애자일의 Rapid Feedback의 좋은 예시인거죠. 또한 외래키, 조인, 그리고 영속화를 고민하는 DB-Driven 이 아닌, 클래스, 메니저, 팩토링 등을 고민하는 OO-Driven이 아닌 Domain-Driven 이라는 개념을 강조하며 설명합니다.</p><blockquote>The design is the code and the code is the design.</blockquote><blockquote>Key DDD Principle: Communicate the design in the code</blockquote><p>FP 에서 코드로 도메인 모델링을 하기 위해서는 ‘Type’ 이 필요하다고 발표자는 언급합니다. Type 은 단순히 어떤 것들을 모아놓은 집합의 이름일 뿐이지만, 이러한 여러 Type 들을 마치 레고처럼 조합하여 사용하는 Composable Type System 을 기반으로 도메인 모델과 그 제약조건을 명확하게 코드로 표현하면서, 비즈니스 요구사항의 변화에 따라 코드와 함께 도메인이 진화해 나가는 과정을 설명하고 있습니다.</p><blockquote>FP Principle: Types are not classes, Composition everywhere</blockquote><p>정리하면, FP 는 타입과 타입의 조합을 이용하여 규칙을 강제하며 도메인 모델을 표현하여 올바른 Input 과 올바른 Output 을 생성하고, 참여자들과 Mental Model 을 공유함으로써 설계 단계에서 빠른 피드백을 수용할 수 있는 방식으로 설계가 가능함을 말하고 있습니다.</p><p>개인적으로는 F#과는 달리 동적 타입 언어인 Clojure 에서는 어떻게 표현할 수 있는지에 대한 궁금증으로 살펴본 위 영상에서 많은 영감과 힌트를 얻을 수 있었고, 다음에는 그 경험을 공유해볼 수 있으면 좋겠습니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef6fa48ed4be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[번역] Transducers 이해하기]]></title>
            <link>https://medium.com/@autumn.bom/%EB%B2%88%EC%97%AD-transducers-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0-c69e07840cc?source=rss-a54053abb683------2</link>
            <guid isPermaLink="false">https://medium.com/p/c69e07840cc</guid>
            <category><![CDATA[transducers]]></category>
            <category><![CDATA[clojure]]></category>
            <dc:creator><![CDATA[Autumn]]></dc:creator>
            <pubDate>Sun, 20 Jan 2019 08:30:24 GMT</pubDate>
            <atom:updated>2019-01-22T02:13:31.312Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understanding Transducers — Elben Shira (2014)</h4><p><em>이 글은 Elben Shira 의 </em><a href="http://elbenshira.com/blog/understanding-transducers/"><strong><em>Understanding Transducers</em></strong></a><em> 를 번역한 글 입니다. 원 저작자의 </em><a href="https://twitter.com/ElbenShira/status/1080159602904190977"><strong><em>동의</em></strong></a><em>를 얻고 진행하였으며, 좀 더 자연스러운 글을 위하여 곳곳에 의역이 들어가 있음을 알려드립니다.</em></p><p><em>This is a translation into Korean of ‘Elben Shira: </em><a href="http://elbenshira.com/blog/understanding-transducers/"><em>Understanding Transducers</em></a><em>’ with agreement with author, Elben. And also it’s translated a bit liberally to better readable.</em></p><p>Transducer 가 무엇일까? Transducer 를 사용하는 건 매우 쉽다. 하지만 그 안에서는 어떻게 동작하고 있는 걸까?</p><p>이 글에서는 Transducer 에 대해 알아보고자 한다. 대신 Transducer 라는 말을 잠시 잊고 평범한 두 개의 함수 map 과 filter 에 대해 살펴보면서 이들을 가지고 활용하며 좀 더 세밀하게 들여다보려고 한다. 그 과정에서 우리는 추상화를 할 때 Higher-Order Function 의 힘에 놀랄 것이고, 아마 운이 좋다면 잊고 있었던 Transducer 를 다시 마주칠 수도 있을 것이다.</p><p>그리고 우리는 Transducer 에 대해 잊기로 하였기 때문에, 이 글이 진행되는 동안 Transducer 무엇인지 알려고 할 필요가 없다. 만약 Clojure 또는 Lisp 을 모른다면 <a href="http://elbenshira.com/p/clojure-primer-js">이 빠른 입문서</a>가 도움이 될 것이다.</p><p>마지막으로, 앞으로 나올 예제들을 자신의 REPL 또는 <a href="http://clojurescript.net/">clojurescript.net</a> 에서 실행해보기를 권장한다. 예제들의 소스코드는 <a href="https://gist.github.com/elben/da8864e120c373e5fcf0">여기서</a> 찾을 수 있다.</p><h3>Power of reduce</h3><p>여러분들은 아마 map 과 filter 에 익숙하며, 아래의 예제처럼 이 둘을 서로 결합하여 사용할 수 있다는 것도 알고 있을 것이다.</p><pre>(<strong>map</strong> <strong>inc</strong> (<strong>range</strong> 10))<br><em>; ⇒ (1 2 3 4 5 6 7 8 9 10)</em></pre><pre>(<strong>filter</strong> <strong>even?</strong> &#39;(1 2 3 4 5 6 7 8 9 10))<br><em>; ⇒ (2 4 6 8 10)</em></pre><pre>(<strong>filter</strong> <strong>even?</strong> (<strong>map</strong> <strong>inc</strong> (<strong>range</strong> 10)))<br><em>; ⇒ (2 4 6 8 10)</em></pre><p>그러나 여기서 중요한 것은 map 과 filter 가 reduce 를 사용하여 정의될 수 있다는 것이다. 그럼 표현식(expression) (map inc (range 10)) 을 reduce 를 사용하여 구현해 보자.</p><pre>(defn map-inc-reducer<br> [result input]<br> (<strong>conj</strong> result (<strong>inc</strong> input)))</pre><pre>(<strong>reduce</strong> map-inc-reducer [] (<strong>range</strong> 10))<br><em>; ⇒ [1 2 3 4 5 6 7 8 9 10]</em></pre><p>그런데 map-inc-reducer 에서 inc 를 transformer 로써 명시적으로 사용했다는 점을 주목하자. 만약 inc 를 함수 밖으로 빼고 그 자리에 어떠한 함수든지 그들이 원하는 함수를 넘기도록 하면 어떨까? 우리는 다시 inc 같은 transforming function 을 받아 새로운 함수를 돌려주는 신규 함수를 정의할 수 있다.</p><pre>(defn map-reducer<br>  [f]<br>  (<strong>fn</strong> [result input]<br>    (<strong>conj</strong> result (f input))))</pre><pre>(<strong>reduce</strong> (map-reducer <strong>inc</strong>) [] (<strong>range</strong> 10))<br><em>; ⇒ [1 2 3 4 5 6 7 8 9 10]</em></pre><p>map-reducer 와 같은 함수들을 Higher-Order Function 이라고 부른다. 왜냐하면 이들은 함수를 받아드리고 함수를 돌려주기 때문이다. 이렇게도 해보자.</p><pre>(<strong>reduce</strong> (map-reducer <strong>dec</strong>) [] (<strong>range</strong> 10))<br><em>; ⇒ [-1 0 1 2 3 4 5 6 7 8]</em></pre><pre>(<strong>reduce</strong> (map-reducer #(* % %)) [] (<strong>range</strong> 10))<br><em>; ⇒ [0 1 4 9 16 25 36 49 64 81]</em></pre><p>이번에는 표현식 (filter even? &#39;(1 2 3 4 5 6 7 8 9 10)) 을 reduce 를 사용하여 구현해 보자.</p><pre>(defn filter-even-reducer<br>  [result input]<br>  (<strong>if</strong> (<strong>even?</strong> input)<br>    (<strong>conj</strong> result input)<br>    result))</pre><pre>(<strong>reduce</strong> filter-even-reducer [] &#39;(1 2 3 4 5 6 7 8 9 10))<br><em>; ⇒ [2 4 6 8 10]</em></pre><p>이번에도 filter-even-reducer 에서 even? 함수를 predicate 로써 명시적으로 사용했음을 주목하자. 앞서 했던 것처럼 even? 함수를 밖으로 빼고 그들이 원하는 함수를 넘길 수 있도록 하자.</p><pre>(defn filter-reducer<br>  [predicate]<br>  (<strong>fn</strong> [result input]<br>    (<strong>if</strong> (predicate input)<br>      (<strong>conj</strong> result input)<br>      result)))</pre><pre>(<strong>reduce</strong> (filter-reducer <strong>even?</strong>) [] &#39;(1 2 3 4 5 6 7 8 9 10))<br><em>; ⇒ [2 4 6 8 10]</em></pre><p>우리는 또한 map-reducer 와 filter-reducer 를 함께 구성할 수도 있다.</p><pre>(<strong>reduce</strong><br>  (filter-reducer <strong>even?</strong>)<br>  []<br>  (<strong>reduce</strong><br>    (map-reducer <strong>inc</strong>)<br>    []<br>    (<strong>range</strong> 10)))<br><em>; ⇒ [2 4 6 8 10]</em></pre><p>위의 표현식과 아래의 표현식은 vector 인지 list 인지를 제외하고는 동등하다.</p><pre>(<strong>filter</strong> <strong>even?</strong> (<strong>map</strong> <strong>inc</strong> (<strong>range</strong> 10)))<br><em>; ⇒ (2 4 6 8 10)</em></pre><p>우리는 High-Order Function 들을 가지고 map, filter 를 reduce 를 사용하여 정의할 수 있음을 알아보았다.</p><p>그러나 두 버전 모두 중간에 vector 들이 필요로 했다 — 하나는 map, 다른 하나는 filter 에서. Transducer 의 중요한 속성 중 하나는, transformation 의 개수와 상관없이 오직 하나의 collection 만 사용해야 한다는 것이다. 어떻게 할 수 있을까?</p><h3>Another step in abstraction</h3><p>map-reducer 와 filter-reducer 를 다시 자세히 들여다보자.</p><pre>(defn map-reducer<br>  [f]<br>  (<strong>fn</strong> [result input]<br>    (<strong>conj</strong> result (f input))))</pre><pre>(defn filter-reducer<br>  [predicate]<br>  (<strong>fn</strong> [result input]<br>    (<strong>if</strong> (predicate input)<br>      (<strong>conj</strong> result input)<br>      result)))</pre><p>무엇이 보이는가? conj 각 양쪽 모두 사용되고 있다. 왜? 이게 무엇이 특별한 걸까? conj 대신 다른 함수들을 사용할 수 있을까?</p><p>자, result 와 input 은 어떤 타입이든 될 수 있음을 주목하자. 만약 result 가 10 이고 input 이 1 이면, (conj 10 1) 에러를 던지며 conj 는 동작하지 않을 것이다. conj 대신 + 같은 것들이기를 원할 것이다. 왜냐하면 (+ 10 1) 은 말이 되기 때문이다.</p><p>conj 와 + 둘 다 <strong>Reducing Function</strong> 이라고 부를 수 있다. Reducing Function 는 result 와 input 을 받아서 새로운 result 를 돌려주는 result, input -&gt; result 타입을 가진다.</p><pre>(<strong>conj</strong> [1 2 3] 4)<br><em>; ⇒ [1 2 3 4]</em></pre><pre>(<strong>+</strong> 10 1)<br><em>; ⇒ 11</em></pre><p>이제, map-reducer 와 filter-reducer 에서 항상 conj 를 사용하는 대신, 그들이 원하는 Reducing Function 을 넘길 수 있도록 하면 어떨까?</p><p>이것은, 이전과 다를 바 없이, 우리가 앞서 만든 map 의 transform 함수, filter 의 predicate 함수를 갖는 또 다른 Higher-Order Function 일 것 이지만, 대신 Reducing Function 받는 함수를 돌려줄 것이다. 이 새로운 함수의 이름을 mapping 과 filtering 으로 하자.</p><pre>(defn mapping<br>  [f]<br>  (<strong>fn</strong> [reducing]<br>    (<strong>fn</strong> [result input]<br>      (reducing result (f input)))))</pre><pre>(defn filtering<br>  [predicate]<br>  (<strong>fn</strong> [reducing]<br>    (<strong>fn</strong> [result input]<br>      (<strong>if</strong> (predicate input)<br>        (reducing result input)<br>        result))))</pre><p>그리고 이 함수들을 전에 했던 방식으로 사용해 보자.</p><pre>(<strong>reduce</strong><br>  ((filtering <strong>even?</strong>) <strong>conj</strong>)<br>  []<br>  (<strong>reduce</strong><br>    ((mapping <strong>inc</strong>) <strong>conj</strong>)<br>    []<br>    (range 10)))<br><em>; ⇒ [2 4 6 8 10]</em></pre><p>여기서 우리는 Reducing Function 을 선택해서 사용할 수 있음을 볼 수 있다. 이번 경우에는 conj 를 선택했다.</p><h3>Arriving at transducers</h3><p>((mapping inc) conj) 와 ((filtering even?) conj) 에 주목하자. 이 함수들의 타입은 result, input -&gt; result 이다. 아래와 같이 테스트해 볼 수 있다.</p><pre>(((mapping <strong>inc</strong>) <strong>conj</strong>) [] 1)<br><em>; ⇒ [2]</em></pre><pre>(((mapping <strong>inc</strong>) <strong>conj</strong>) [2] 2)<br><em>; ⇒ [2 3]</em></pre><pre>(((mapping <strong>inc</strong>) <strong>conj</strong>) [2 3] 3)<br><em>; ⇒ [2 3 4]</em></pre><pre>(((filtering <strong>even?</strong>) <strong>conj</strong>) [2 4] 5)<br><em>; ⇒ [2 4]</em></pre><pre>(((filtering <strong>even?</strong>) <strong>conj</strong>) [2 4] 6)<br><em>; ⇒ [2 4 6]</em></pre><p>이것은 즉, ((mapping inc) conj) 와 ((filtering even?) conj) 또한 conj 와 + 와 같은<strong> Reducing Function</strong> 이라는 의미이다.</p><p>그럼 이 두 함수를 아래와 같이 구성해보면 어떻게 될까?</p><pre>((mapping <strong>inc</strong>) ((filtering <strong>even?</strong>) <strong>conj</strong>))</pre><p>이 또한 함수이다. 근데 이 함수의 타입이 뭘까? 바로 evaluate 해보자.</p><p>이 함수의 타입 <em>또한</em> result, input -&gt; result 임이 드러났다. 이 역시 Reducing Function 이다. 즉, 이 함수를 reduce 함수를 통해 사용할 수 있다는 의미이다.</p><pre>(<strong>reduce</strong> ((mapping <strong>inc</strong>) ((filtering <strong>even?</strong>) <strong>conj</strong>)) [] (<strong>range</strong> 10))<br><em>; ⇒ [2 4 6 8 10]</em></pre><p>좀 지저분해 보인다. 대신에 comp 를 사용하여 정리해보자. 우선 (comp a b c d) 가 돌려주는 함수에 대해 떠올려보자.</p><pre>(fn [r] (a (b (c (d r)))))</pre><p>여기에 comp 를 이용한 정리된 버전이 있다.</p><pre>(def xform<br>  (<strong>comp</strong><br>    (mapping <strong>inc</strong>)<br>    (filtering <strong>even?</strong>)))</pre><pre>(<strong>reduce</strong> (xform <strong>conj</strong>) [] (<strong>range</strong> 10))<br><em>; ⇒ [2 4 6 8 10]</em></pre><p>그리고 좀 더 복잡한 건 어떨까?</p><pre>(defn square [x] (* x x))</pre><pre>(def xform<br>  (<strong>comp</strong><br>    (filtering <strong>even?</strong>) <br>    (filtering #(&lt; % 10))<br>    (mapping square)<br>    (mapping inc)))</pre><pre>(<strong>reduce</strong> (xform <strong>conj</strong>) [] (<strong>range</strong> 10))<br>; ⇒ [1 5 17 37 65]</pre><p>아름답다.</p><p>근데 우리는 Transducer 에 대해 이야기 하고 있었다. 우리의 Transducer 는 어디 있는가?</p><p>지금까지 살펴본 것으로, mapping 과 filtering 은 Transducer 를 돌려주는 함수이고, (mapping inc), (filtering even?), xform 함수들이 <strong>우리가 찾던 진짜 Transducer 이다.</strong></p><p>Transducer 는 Reducing Function 을 받아서 Reducing Function 을 돌려주는 함수이다. 예를 들어, 위에서 살펴본 바로, (mapping inc) 는 conj 같은 Reducing Function 을 인자로 받고, 다른 Reducing Function 을 돌려보내기 때문에 Transducer 이다. <a href="http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming">Transducers are coming</a> 에서 Rich Hickey 가 언급했듯이 Transducer 는 아래의 타입을 가지고 있다.</p><pre>(result, input -&gt; result) -&gt; (result, input -&gt; result)</pre><p>또한 (reduce (xform conj) [] (range 10)) 을 evaluate 할 때 초기 벡터 외에는 중간에 collection 들을 만들지 않음을 보자. 이는 중간 collection 을 만들지 않는다는 우리의 목표를 만족시켜주고 있다.</p><h3>A more intuitive understanding</h3><p>xform Transducer 가 왜 동작하는지 이해하는 건 아마 어려울 것이다. 왜냐하면 꽤 복잡하니까. 그래도 좀 더 이해해보도록 해보자. 이전에 만든 xform 이다.</p><pre>(defn square [x] (* x x))</pre><pre>(def xform<br>  (<strong>comp</strong><br>    (filtering <strong>even?</strong>)<br>    (filtering #(&lt; % 10))<br>    (mapping square)<br>    (mapping <strong>inc</strong>)))</pre><p>Reducing Function 을 넘겨받는 이 Composed Function 을 호출한다고 하자. 아마 우리가 좋아하는 conj 를 넘기겠지. 그러면 넘겨받은 conj 를 (mapping inc) Transducer 에 넘기고 ((mapping inc) conj) 를 돌려받을 것이다. 우리는 이것이 또 다른 Reducing Function 이라는 것을 안다. 그럼 이 새로운 Reducing Function 은 또 다른 Transducer 인 (mapping square) 에 넘겨지게 되고 당연히 또 다른 Reducing Function 을 돌려 받게 될 것이다. 이런식으로 xform 을 구성하는 첫 번째 Transducer (filtering even?) 까지 실행하게 된다.</p><p>이는, (xform conj) 처럼 xform 에 Reduction Function 을 넘기면, 가장 왼쪽의 Reducing Function 부터 단계적으로 적용하여 마지막 Reducing Function 인 conj 에 현재의 result 와 input 값을 넘기는 함수를 얻는다는 의미이다.</p><p>이 Transducer 가 어떤 Reduce 함수에서 사용된다고 생각해 보자. 그리고 이제까지 result 벡터에 [1 5 17] 을 모았다고 하자. 문제의 input 은 12. 12 는 짝수이기 때문에 첫 번째 필터를 통과할 것 이다. 그럼 이 첫 번째 필터는 자신의 Reducing Function 을 호출할 것이다. 이 경우에는 Transformation 의 나머지인 두 번째 필터 #(&lt; % 10) 이다. 12 는 두 번째 필터에서 실패하기 때문에, 세 번째 Reducing Function 는<em> 호출되지 않는다</em>. 그리고 지금까지의 result [1 5 17] 이 반환하게 된다.</p><p>그러나 만약 input 이 6 이면, 두 개의 필터 모두 통과하여 mapping transform 들에게 도착하고 6 은 37 로 변환될 것이다. 그럼 이 값을 가장 마지막 Reducing Function 인 conj 에 input 으로 넘기고 [1 5 17] 과 합치게 될 것이다.</p><pre>((xform <strong>conj</strong>) [1 5 17] 12)<br>; ⇒ [1 5 17]</pre><pre>((xform <strong>conj</strong>) [1 5 17] 6)<br>; ⇒ [1 5 17 37]</pre><pre>(<strong>reduce</strong> (xform <strong>conj</strong>) [] (<strong>range</strong> 10))<br>; ⇒ [1 5 17 37 65]</pre><p>Transducer 를 구성할 수 있다는 것은 중요하다. 우리는 그렇게 하는 것이 꽤 간단하고 평범한 함수들의 힘이 전부라는 것을 보았다.</p><h3>Transducers in core.async</h3><p>또 다른 Transducer 의 주요한 장점은 core.async 채널 간에 동작할 수 있다는 것이다. 예를 들면, 우리가 만든 xform Transducer 를 가지고 채널 안에서 필터링하고 변환할 수 있어야 한다.</p><p>Clojure 의 Transducer 라이브러리를 사용한 것이다.</p><pre>(defn square [x] (* x x))</pre><pre>(def xform<br>  (comp<br>    (<strong>filter</strong> <strong>even?</strong>)<br>    (<strong>filter</strong> #(&lt; % 10))<br>    (<strong>map</strong> square)<br>    (<strong>map</strong> <strong>inc</strong>)))</pre><pre>(def my-chan (async/chan 1 xform))</pre><pre><em>; 출력할 item 을 기다린다.<br></em>(async/take! my-chan <strong>println</strong>)</pre><pre>(async/put! my-chan 3)<br><em>; 3은 짝수 이기 때문에, 화면에 출력되지 않는다.</em></pre><pre>(async/put! my-chan 4)<br><em>; 4는 짝수 이고 10보다 작기 때문에, &quot;17&quot;이 화면에 출력된다.</em></pre><p>Transducer 들이 core.async 채널 간에 어떻게 동작하는가?</p><p>우선, 채널 버퍼들은 내부에서 리스트로 연결되어 있다는 것을 주목하자. (사실 java.util.LinkedList 들이다.) 채널에 item 을 넣을 때, 내부 헬퍼 메소드인 add! 가 버퍼에 그 item 을 추가하기 위해 호출된다.</p><p>하지만 만약 xform Transducer 가 주어진다면, core.async 는 xform 에 넘겨질 Reducing Function 으로 add! 를 사용할 것이다.</p><pre>(xform add!)</pre><p>이 뜻은, 어떤 item 이던 채널에 넣으면 우선 우리의 Transducer, xform, 에 의해 변환될 것이다. 그리고 만약 그 item 이 filter 를 통과 못 하면 (예를 들어, (filter even?) 때문에), 마지막 Reducing Function 인 add! 는 한 번도 호출되지 않는다. 그러므로 그 item 은 결코 채널의 버퍼에 추가되지 않으며 어떤 수신자들도 그 item 을 볼 수가 없다는 의미이다.</p><p>관련 코드들은 core.async 소스 파일 에서 찾을 수 있다. <a href="https://github.com/clojure/core.async/blob/ac0f1bfb40237a18dc0f03c0db5df41657cd23a6/src/main/clojure/clojure/core/async/impl/channels.clj#L287">여기</a>.</p><h3>Conclusion</h3><p>먼 길을 왔다. 우리는 일반적인 map 과 filter 그리고 reduce 를 사용하여 그 들이 어떻게 구현될 수 있는지 살펴보는 것으로 시작하여, Transducer 를 만드는 함수인 mapping 과 filtering 을 만날 때까지 Reducing Function 들을 추상화하였다.</p><p>만들고, 분석하고, Transducer 들을 사용하는 것으로, 그것이 어떻게 동작하는지 좀 더 이해했기를 바란다. 그것들도 결국 그냥 함수일 뿐이다.</p><h3>Problem sets</h3><p>만약 좀 더 배우는 것에 관심이 있다면, 아래의 문제들을 한번 도전해보기를 권장한다. 해법은 <a href="https://gist.github.com/elben/da8864e120c373e5fcf0#file-understanding-transducers-clj-L204">여기서</a> 찾을 수 있다.</p><p><strong>Write a </strong>transduce<strong> helper function</strong></p><p>현재 우리가 사용하는 reduce 는 다소 투박하다. 아래처럼 Transducer 를 사용할 수 있도록 transduce 함수를 작성하라.</p><pre>(transduce xform conj [] (range 10))<br>; ⇒ [5 17 37 65]</pre><p><strong>The Caesar Cipher</strong></p><p>위에 있는 예제들에서, 우리는 conj 와 + 를 Reducing Function 으로서 사용했다. 좀 더 복잡한 걸 만들어 보자.</p><p>주어진 문자열을 아래와 같이 변환하는 Transducer 사용하기:</p><ul><li>모음과 non-ASCII 문자 걸러 내기.</li><li>대문자 걸러 내기.</li><li>남은 문자를 <a href="http://en.wikipedia.org/wiki/Caesar_cipher">Caesar cipher</a> 로 순환하기.</li><li>그리고 순환된 문자들을 reduce 하면서 문자마다 발생 빈도수 를 map 에 담기.</li></ul><p>예:</p><pre>(defn caesar-count<br>  [string cipher]<br>  ???)</pre><pre>(caesar-count &quot;abc&quot; 0)<br>; ⇒ {\c 1, \b 1}</pre><pre>(caesar-count &quot;abc&quot; 1)<br>; ⇒ {\d 1, \c 1}</pre><pre>(caesar-count &quot;hello world&quot; 0)<br>; ⇒ {\d 1, \r 1, \w 1, \l 3, \h 1}</pre><pre>(caesar-count &quot;hello world&quot; 13)<br>; ⇒ {\q 1, \e 1, \j 1, \y 3, \u 1}</pre><p><strong>Write a </strong>mapcat<strong> transducer</strong></p><p>mapcat Transducer 를 돌려주는 mapcatting 함수 작성하기.</p><p>Transducer 가 아닌 mapcat 의 예제:</p><pre>(defn twins [x] [x x])</pre><pre>(mapcat twins (range 10))<br>; ⇒ (0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9</pre><p>이 Transducer 는 아래와 같이 동작해야 한다.</p><pre>(defn mapcatting [f] ???)</pre><pre>(reduce ((mapcatting twins) conj) [] (range 10))<br>; ⇒ [0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9]</pre><p><strong>Write a </strong>take<strong> transducer</strong></p><p>take Transducer 를 돌려taking 함수 작성하기.</p><pre>(defn taking [n] ???)</pre><pre>(reduce ((taking 3) conj) [] (range 10))<br>; ⇒ [0 1 2]</pre><p>이를 위해 몇 가지 상태는 유지해야 할 필요가 있음을 유의해야 한다.</p><h3>References</h3><ul><li><a href="https://gist.github.com/elben/da8864e120c373e5fcf0">이 글의 소스 코드</a></li><li><a href="http://phuu.net/2014/08/31/csp-and-transducers.html">Tom Ashworth: CSP and transducers in JavaScript</a>. Transducer 에 대해 이해 하도록 도와준 블로그 포스트.</li><li><a href="http://blog.cognitect.com/blog/2014/8/6/transducers-are-coming">Rich Hickey: Transducers are coming</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c69e07840cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Run Postman tests with Newman in Gitlab CI]]></title>
            <link>https://medium.com/@autumn.bom/run-postman-tests-with-newman-in-gitlab-ci-c34bc90e17ec?source=rss-a54053abb683------2</link>
            <guid isPermaLink="false">https://medium.com/p/c34bc90e17ec</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[newman]]></category>
            <category><![CDATA[gitlab-ci]]></category>
            <category><![CDATA[postman]]></category>
            <category><![CDATA[gitlab]]></category>
            <dc:creator><![CDATA[Autumn]]></dc:creator>
            <pubDate>Sat, 01 Sep 2018 15:53:51 GMT</pubDate>
            <atom:updated>2018-09-01T15:53:51.133Z</atom:updated>
            <content:encoded><![CDATA[<h4>for your integration testing</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*iRmKxHeqm2Wi6f429bT8gA.png" /></figure><p>In this article, let me show you how to run Postman tests in Gitlab CI/CD pipeline. Basically, we’re working with api and testing on web or client but in order to run Postman tests while pipeline progress, we need to use Newman which a runner to run and test a Postman collection from the command-line.</p><h3>1. Generate an API Key</h3><p>First, we have to get an Postman API Key, because it’s needed to get collection and environment url via Postman API for running tests with Newman.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*sLsx1NYZnyHSxuZ7x-OJLw.png" /><figcaption>Integrations &gt; Postman API</figcaption></figure><ol><li><em>Go to web &gt; Choose workspace &gt; Tab ‘Integrations’</em></li><li><em>Tab ‘Browse Integraions’ &gt; Choose ‘Postman API’ &gt; Click ‘+ Get API Key’</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4188xWWsS9VZKtNb2vcZiw.png" /><figcaption>Take it!</figcaption></figure><h3>2. Get the Collection URL</h3><p>It takes two steps to get the collection url to test via Postman API with the API key. One step is that fetch a list of your collection and get a uid of the collection to test in the list. Last step is that get the collection url with the uid from previous step.</p><h4>2.1 Fetch a collection list &amp; Get a `uid` of the collection</h4><pre>https://api.getpostman.com/collections?apikey=${apiKey}</pre><h4>2.2 Get the collection url</h4><pre>https://api.getpostman.com/collections/${c_uid}?apikey=${apiKey}</pre><h3>3. Get the Environment URL</h3><p>It’s the same as above getting the collection url.</p><h4>3.1 Fetch a environment list &amp; Get a ‘uid’ of the environment</h4><pre>https://api.getpostman.com/environments?apikey=${apiKey}</pre><h4>3.2 Get the environment url</h4><pre>https://api.getpostman.com/environments/${e_uid}?apikey=${apiKey}</pre><h3>4. .gitlab-ci.yml</h3><p>Last, to run Postman test in Gitlab CI/CD, let’s add a job which call Newman ‘run’ command in the pipeline to the .gitlab-ci.yml. There are two cases whether based on docker or not. If without docker, it needs to install Newman in before_script. Otherwise, wojciechzurek/newman-ci docker image helps you not have to the install it.</p><h4>Without docker</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1e2c3dd25fdf54929337e42e4c599e3/href">https://medium.com/media/d1e2c3dd25fdf54929337e42e4c599e3/href</a></iframe><h4>With docker</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/feff8e02c3f497c769d4347b546418aa/href">https://medium.com/media/feff8e02c3f497c769d4347b546418aa/href</a></iframe><h3>Ref.</h3><ul><li>Command line integration with Newman — Postman : <a href="https://www.getpostman.com/docs/v6/postman/collection_runs/command_line_integration_with_newman">https://www.getpostman.com/docs/v6/postman/collection_runs/command_line_integration_with_newman</a></li><li>Newman : <a href="https://github.com/postmanlabs/newman#using-newman-with-the-postman-api">https://github.com/postmanlabs/newman</a></li><li>Newman-ci : <a href="https://github.com/wojciech-zurek/newman-ci">https://github.com/wojciech-zurek/newman-ci</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c34bc90e17ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Spring Boot Jar Application on Beanstalk Java SE Platform]]></title>
            <link>https://medium.com/@autumn.bom/deploying-spring-boot-jar-application-on-beanstalk-java-se-platform-45d8d04608ae?source=rss-a54053abb683------2</link>
            <guid isPermaLink="false">https://medium.com/p/45d8d04608ae</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[elastic-beanstalk]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[executable-jar]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Autumn]]></dc:creator>
            <pubDate>Mon, 16 Apr 2018 02:06:46 GMT</pubDate>
            <atom:updated>2018-04-16T02:06:46.131Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we’re going to take a look at how to deploy executable jar spring boot application to beanstalk java se platform, not tomcat platform.</p><h3>1. Creating an executable jar</h3><p>To create spring boot executable jar, you should use build tool to support spring boot packing. Here’s two ways depends on what you use.</p><h4><a href="https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/reference/htmlsingle/#getting-started-first-application-executable-jar">Maven</a></h4><ol><li>add the spring-boot-maven-plugin to pom.xml</li><li>run mvn package</li><li><em>myapplication.</em>jar is created in target directory</li></ol><h4><a href="https://docs.spring.io/spring-boot/docs/2.0.1.RELEASE/gradle-plugin/reference/html/#packaging-executable-jars">Gradle</a></h4><ol><li>add the spring-boot-gradle-plugin to build.gradle</li><li>run ./gradlew bootJar</li><li><em>myapplication.</em>jar is created in build/lib directory</li></ol><h3>2. <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-procfile.html">Procfile</a></h3><p>Basically, beanstalk can run your application without Procfile in your source bundle if you have a only one jar file. In this case, beanstalk will run it with java -jar <em>myapplication</em>.jar without any jvm options. If you want to customize the java command to set jvm options, you should include Procfile in your source bundle even though only one jar use.</p><pre>web: java -Dfile.encoding=UTF-8 -Xms2g -Xmx2g -jar my<em>application</em>.jar</pre><h3>3. <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html">Create a source bundle</a></h3><p>Then, we should create a source bundle include <em>myapplication</em>.jar Procfile and <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html">.ebextensions</a> if you want to apply settings. Note that Procfile and .ebextensions should be in your source bundle root.</p><pre>zip -r <em>my_source_bundle</em>.zip my<em>application</em>.jar .ebextensions Procfile</pre><h3>4. Deploying source bundle</h3><p>Now, You can deploy the source bundle to beanstalk with eb deploy <a href="https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-getting-started.html">EB CLI </a>or Beanstalk web consol. if you use eb deploy EB CLI, you should deploy artifact which is source bundle in .elasticbeanstalk/config.yml</p><pre><strong>deploy:<br>  artifact: </strong><em>my_source_bundle</em>.zip</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45d8d04608ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>